Class: Promoted::Ruby::Client::RequestBuilder
- Inherits:
-
Object
- Object
- Promoted::Ruby::Client::RequestBuilder
- Defined in:
- lib/promoted/ruby/client/request_builder.rb
Instance Attribute Summary collapse
-
#client_info ⇒ Object
readonly
Returns the value of attribute client_info.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#experiment ⇒ Object
readonly
Returns the value of attribute experiment.
-
#insertion ⇒ Object
Returns the value of attribute insertion.
-
#only_log ⇒ Object
readonly
Returns the value of attribute only_log.
-
#platform_id ⇒ Object
Returns the value of attribute platform_id.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#timing ⇒ Object
Returns the value of attribute timing.
-
#use_case ⇒ Object
readonly
Returns the value of attribute use_case.
-
#user_info ⇒ Object
Returns the value of attribute user_info.
-
#view_id ⇒ Object
readonly
Returns the value of attribute view_id.
Instance Method Summary collapse
- #add_missing_insertion_ids!(insertions) ⇒ Object
- #client_request_id ⇒ Object
- #delivery_request_params ⇒ Object
- #ensure_client_timestamp ⇒ Object
-
#initialize(args = {}) ⇒ RequestBuilder
constructor
A new instance of RequestBuilder.
-
#new_cohort_membership_to_log ⇒ Object
Only used in delivery.
-
#set_request_params(args = {}) ⇒ Object
Populates request parameters from the given arguments, presumed to be a hash of symbols.
Constructor Details
#initialize(args = {}) ⇒ RequestBuilder
Returns a new instance of RequestBuilder.
10 11 12 13 14 15 16 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 10 def initialize args = {} if args[:id_generator] @id_generator = args[:id_generator] else @id_generator = IdGenerator.new end end |
Instance Attribute Details
#client_info ⇒ Object (readonly)
Returns the value of attribute client_info.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def client_info @client_info end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def device @device end |
#experiment ⇒ Object (readonly)
Returns the value of attribute experiment.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def experiment @experiment end |
#insertion ⇒ Object
Returns the value of attribute insertion.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def insertion @insertion end |
#only_log ⇒ Object (readonly)
Returns the value of attribute only_log.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def only_log @only_log end |
#platform_id ⇒ Object
Returns the value of attribute platform_id.
8 9 10 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 8 def platform_id @platform_id end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def request @request end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def request_id @request_id end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def session_id @session_id end |
#timing ⇒ Object
Returns the value of attribute timing.
8 9 10 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 8 def timing @timing end |
#use_case ⇒ Object (readonly)
Returns the value of attribute use_case.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def use_case @use_case end |
#user_info ⇒ Object
Returns the value of attribute user_info.
8 9 10 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 8 def user_info @user_info end |
#view_id ⇒ Object (readonly)
Returns the value of attribute view_id.
5 6 7 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 5 def view_id @view_id end |
Instance Method Details
#add_missing_insertion_ids!(insertions) ⇒ Object
78 79 80 81 82 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 78 def add_missing_insertion_ids! insertions insertions.each do |insertion| insertion[:insertion_id] = @id_generator.newID if not insertion[:insertion_id] end end |
#client_request_id ⇒ Object
84 85 86 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 84 def client_request_id request[:client_request_id] end |
#delivery_request_params ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 52 def delivery_request_params params = { user_info: user_info, timing: timing, client_info: merge_client_info_defaults, device: @device, platform_id: @platform_id, view_id: @view_id, session_id: @session_id, use_case: @use_case, search_query: request[:search_query], properties: request[:properties], paging: request[:paging], client_request_id: client_request_id } params[:insertion] = insertion params.clean! end |
#ensure_client_timestamp ⇒ Object
72 73 74 75 76 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 72 def if timing[:client_log_timestamp].nil? timing[:client_log_timestamp] = (Time.now.to_f * 1000).to_i end end |
#new_cohort_membership_to_log ⇒ Object
Only used in delivery
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 38 def new_cohort_membership_to_log return nil unless @experiment if !@experiment[:platform_id] && @platform_id @experiment[:platform_id] = @platform_id end if !@experiment[:user_info] && @user_info @experiment[:user_info] = @user_info end if !@experiment[:timing] && @timing @experiment[:timing] = @timing end return @experiment end |
#set_request_params(args = {}) ⇒ Object
Populates request parameters from the given arguments, presumed to be a hash of symbols.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/promoted/ruby/client/request_builder.rb', line 19 def set_request_params args = {} @request = args[:request] || {} @experiment = args[:experiment] @only_log = args[:only_log] @session_id = request[:session_id] @platform_id = request[:platform_id] @client_info = request[:client_info] || {} @device = request[:device] || {} @view_id = request[:view_id] @use_case = Promoted::Ruby::Client::USE_CASES[request[:use_case]] || Promoted::Ruby::Client::USE_CASES['UNKNOWN_USE_CASE'] @insertion = request[:insertion] || [] @user_info = request[:user_info] || { :user_id => nil, :anon_user_id => nil} @timing = request[:timing] || { :client_log_timestamp => (Time.now.to_f * 1000).to_i } # If the user didn't create a client request id, we do it for them. request[:client_request_id] = request[:client_request_id] || @id_generator.newID end |