-
Notifications
You must be signed in to change notification settings - Fork 1
Fix/change parameters names v.0.9 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
OriaLogic
wants to merge
6
commits into
v.0.9
Choose a base branch
from
fix/change-parameters-names-v.0.9
base: v.0.9
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de2dde7
See branch name
OriaLogic e189877
Reuse :email instead of email_uid
OriaLogic b52c2c9
Reuse email instead of email_uid everywher
OriaLogic 7db6759
Added test of emails and flush after email enqueue
OriaLogic 9761176
Change to batch mode
OriaLogic 81ffe37
Changed api_key to api_token and fixed method pageview to method event
OriaLogic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,20 +12,20 @@ class Client | |
| # public: Creates a new client | ||
| # | ||
| # attrs - Hash | ||
| # :api_key - String of your project's api_key | ||
| # :api_token - String of your project's api_token | ||
| # :max_queue_size - Fixnum of the max calls to remain queued (optional) | ||
| # :on_error - Proc which handles error calls from the API | ||
| def initialize attrs = {} | ||
| symbolize_keys! attrs | ||
|
|
||
| @queue = Queue.new | ||
| @api_key = attrs[:api_key] | ||
| @api_token = attrs[:api_token] | ||
| @max_queue_size = attrs[:max_queue_size] || Config::Queue::MAX_SIZE | ||
| @options = attrs | ||
| @worker_mutex = Mutex.new | ||
| @worker = Worker.new @queue, @api_key, @options | ||
| @worker = Worker.new @queue, @api_token, @options | ||
|
|
||
| check_api_key! | ||
| check_api_token! | ||
|
|
||
| at_exit { @worker_thread && @worker_thread[:should_exit] = true } | ||
| end | ||
|
|
@@ -46,23 +46,23 @@ def flush | |
| # attrs - Hash | ||
| def track attrs | ||
| symbolize_keys! attrs | ||
| check_contact_id! attrs | ||
| check_contact_uid! attrs | ||
|
|
||
| event = attrs[:event] | ||
| event_uid = attrs[:event_uid] | ||
| params = attrs[:params] || {} | ||
| created_at = attrs[:created_at] || Time.new | ||
|
|
||
| check_timestamp! created_at | ||
|
|
||
| if event.nil? || event.empty? | ||
| fail ArgumentError, 'Must supply event as a non-empty string' | ||
| if event_uid.nil? || event_uid.empty? | ||
| fail ArgumentError, 'Must supply event_uid as a non-empty string' | ||
| end | ||
|
|
||
| fail ArgumentError, 'Params must be a Hash' unless params.is_a? Hash | ||
| isoify_dates! params | ||
|
|
||
| enqueue({ | ||
| :event => event, | ||
| :event_uid => event_uid, | ||
| :contact_uid => attrs[:contact_uid], | ||
| :params => params, | ||
| :created_at => datetime_in_iso8601(created_at), | ||
|
|
@@ -75,35 +75,39 @@ def track attrs | |
| # attrs - Hash | ||
| def email attrs | ||
| symbolize_keys! attrs | ||
| check_contact_id! attrs | ||
| check_contact_uid! attrs | ||
|
|
||
| email = attrs[:email] | ||
| params = attrs[:params] || {} | ||
| created_at = attrs[:created_at] || Time.new | ||
|
|
||
| check_timestamp! created_at | ||
|
|
||
| if email.nil? || evemailent.empty? | ||
| if email.nil? || email.empty? | ||
| fail ArgumentError, 'Must supply email template as a non-empty string' | ||
| end | ||
|
|
||
| fail ArgumentError, 'Params must be a Hash' unless params.is_a? Hash | ||
| isoify_dates! params | ||
|
|
||
| enqueue({ | ||
| :event => event, | ||
| msg = enqueue({ | ||
| :email => email, | ||
| :contact_uid => attrs[:contact_uid], | ||
| :params => params, | ||
| :created_at => datetime_in_iso8601(created_at), | ||
| :method => 'email' | ||
| }) | ||
|
|
||
| flush if msg | ||
| msg | ||
| end | ||
|
|
||
|
|
||
| def contact attrs | ||
| symbolize_keys! attrs | ||
| check_contact_id! attrs | ||
| check_contact_uid! attrs | ||
|
|
||
| contact_uid = attrs[:contact_uid] | ||
| params = attrs[:params] || {} | ||
| created_at = attrs[:created_at] || Time.new | ||
|
|
||
|
|
@@ -113,7 +117,7 @@ def contact attrs | |
| isoify_dates! params | ||
|
|
||
| enqueue({ | ||
| :contact_uid => attrs[:contact_uid], | ||
| :contact_uid => contact_uid, | ||
| :params => params, | ||
| :created_at => datetime_in_iso8601(created_at), | ||
| :method => 'contact' | ||
|
|
@@ -123,7 +127,7 @@ def contact attrs | |
|
|
||
| def account(attrs) | ||
| symbolize_keys! attrs | ||
| fail ArgumentError, 'Must supply a contact_uid' unless attrs[:account_uid] | ||
| fail ArgumentError, 'Must supply a account_uid' unless attrs[:account_uid] | ||
|
|
||
| account_uid = attrs[:account_uid] | ||
| params = attrs[:params] || {} | ||
|
|
@@ -144,7 +148,7 @@ def account(attrs) | |
|
|
||
| def pageview(attrs) | ||
| symbolize_keys! attrs | ||
| check_contact_id! attrs | ||
| check_contact_uid! attrs | ||
|
|
||
| params = attrs[:params] || {} | ||
| created_at = attrs[:created_at] || Time.new | ||
|
|
@@ -156,80 +160,77 @@ def pageview(attrs) | |
|
|
||
| enqueue({ | ||
| :contact_uid => attrs[:contact_uid], | ||
| :event => "pageview", | ||
| :event_uid => "pageview", | ||
| :params => attrs[:params], | ||
| :created_at => datetime_in_iso8601(created_at), | ||
| :method => 'pageview' | ||
| :method => 'event' | ||
| }) | ||
| end | ||
|
|
||
| # public: Returns the number of queued messages | ||
| # | ||
| # returns Fixnum of messages in the queue | ||
| def queued_messages | ||
| def queued_nb | ||
| @queue.length | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # private: Enqueues the action. | ||
| # | ||
| # returns Boolean of whether the item was added to the queue. | ||
| def enqueue(action) | ||
| # add our request id for tracing purposes | ||
| action[:messageId] = uid | ||
| unless queue_full = @queue.length >= @max_queue_size | ||
| ensure_worker_running | ||
| @queue << action | ||
| # private: Enqueues the action. | ||
| # | ||
| # returns Boolean of whether the item was added to the queue. | ||
| def enqueue(action) | ||
| # add our request id for tracing purposes | ||
| action[:messageId] = create_uid() | ||
| unless queue_full = @queue.length >= @max_queue_size | ||
| ensure_worker_running | ||
| @queue << action | ||
| end | ||
| queue_full ? !queue_full : action | ||
| end | ||
| !queue_full | ||
| end | ||
|
|
||
| # private: Ensures that a string is non-empty | ||
| # | ||
| # obj - String|Number that must be non-blank | ||
| # name - Name of the validated value | ||
| # | ||
| def check_presence!(obj, name) | ||
| if obj.nil? || (obj.is_a?(String) && obj.empty?) | ||
| fail ArgumentError, "#{name} must be given" | ||
| # private: Ensures that a string is non-empty | ||
| # | ||
| # obj - String|Number that must be non-blank | ||
| # name - Name of the validated value | ||
| # | ||
| def check_presence!(obj, name) | ||
| if obj.nil? || (obj.is_a?(String) && obj.empty?) | ||
| fail ArgumentError, "#{name} must be given" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # private: Adds contextual information to the call | ||
| # | ||
| # context - Hash of call context | ||
| def add_context(context) | ||
| context[:library] = { :name => "salesmachine-ruby", :version => Salesmachine::Api::VERSION.to_s } | ||
| end | ||
| # private: Adds contextual information to the call | ||
| # | ||
| # context - Hash of call context | ||
| def add_context(context) | ||
| context[:library] = { :name => "salesmachine-ruby", :version => Salesmachine::Api::VERSION.to_s } | ||
| end | ||
|
|
||
| # private: Checks that the api_key is properly initialized | ||
| def check_api_key! | ||
| fail ArgumentError, 'Api key must be initialized' if @api_key.nil? | ||
| end | ||
| # private: Checks that the api_token is properly initialized | ||
| def check_api_token! | ||
| fail ArgumentError, 'Api key must be initialized' if @api_token.nil? | ||
| end | ||
|
|
||
| # private: Checks the timstamp option to make sure it is a Time. | ||
| def check_timestamp!(timestamp) | ||
| fail ArgumentError, 'Timestamp must be a Time' unless timestamp.is_a? Time | ||
| end | ||
| # private: Checks the timstamp option to make sure it is a Time. | ||
| def check_timestamp!(timestamp) | ||
| fail ArgumentError, 'Timestamp must be a Time' unless timestamp.is_a? Time | ||
| end | ||
|
|
||
| def check_contact_id! attrs | ||
| fail ArgumentError, 'Must supply a contact_uid' unless attrs[:contact_uid] | ||
| end | ||
| def check_contact_uid! attrs | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Except for the name of this function |
||
| fail ArgumentError, 'Must supply a contact_uid' unless attrs[:contact_uid] | ||
| end | ||
|
|
||
| def ensure_worker_running | ||
| return if worker_running? | ||
| @worker_mutex.synchronize do | ||
| def ensure_worker_running | ||
| return if worker_running? | ||
| @worker_thread = Thread.new do | ||
| @worker.run | ||
| @worker_mutex.synchronize do | ||
| return if worker_running? | ||
| @worker_thread = Thread.new do | ||
| @worker.run | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def worker_running? | ||
| @worker_thread && @worker_thread.alive? | ||
| end | ||
| def worker_running? | ||
| @worker_thread && @worker_thread.alive? | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the file did not change, I only indented to highlight the fact that following methods are private