Module: NitroApi::UserCalls
- Included in:
- NitroApi
- Defined in:
- lib/nitro_api/user_calls.rb
Instance Method Summary collapse
- #make_action_history_call(actions = []) ⇒ Object
- #make_award_challenge_call(challenge) ⇒ Object
- #make_challenge_progress_call(opts = {}) ⇒ Object
- #make_get_points_balance_call(opts = {}) ⇒ Object
- #make_join_group_call(group) ⇒ Object
- #make_log_action_call(actions, opts = {}) ⇒ Object
- #make_login_call ⇒ Object
Instance Method Details
#make_action_history_call(actions = []) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/nitro_api/user_calls.rb', line 94 def make_action_history_call actions=[] # TODO: add support for the user.getActionHistory call to nitroapi if not @batch.nil? raise NitroError.new(10000), "user.getActionHistory not supported in batch mode by nitroapi" end params = { :sessionKey => @session, :method => 'user.getActionHistory' } if actions && !actions.empty? params[:tags] = actions.is_a?(Array) ? actions.join(",") : actions end response = make_call(params) if valid_response?(response['ActionHistoryRecord']) items = ensure_array(response['ActionHistoryRecord']['ActionHistoryItem']) items.reduce([]) do |history, item| history<< {:tags => item['tags'], :ts => Time.at(item['ts'].to_i), :value => item['value'].to_i } end else [] end end |
#make_award_challenge_call(challenge) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/nitro_api/user_calls.rb', line 84 def make_award_challenge_call(challenge) params = { :sessionKey => @session, :userId => @user, :method => 'user.awardChallenge', :challenge => challenge } make_call(params) end |
#make_challenge_progress_call(opts = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/nitro_api/user_calls.rb', line 40 def make_challenge_progress_call opts={} # TODO: add support for the user.getChallengeProgress call to nitroapi if not @batch.nil? raise NitroError.new(10000), "user.getChallengeProgress not supported in batch mode by nitroapi" end params = { :sessionKey => @session, :method => 'user.getChallengeProgress' } challenge = opts[:challenge] params['challengeName'] = challenge if challenge and !challenge.to_s.empty? params['showOnlyTrophies'] = opts.delete(:trophies_only) || false params['folder'] = opts.delete(:folder) if opts.has_key?(:folder) response = make_call(params) if valid_response?(response['challenges']) items = ensure_array(response['challenges']['Challenge']) items.reduce([]) do |challenges, item| challenge = Challenge.new challenge.name = item["name"] challenge.description = item["description"] challenge.full_url = item["fullUrl"] challenge.thumb_url = item["thumbUrl"] challenge.completed = item["completionCount"].to_i if valid_response?(item["rules"]) ensure_array(item["rules"]['Rule']).each do |rule_elm| rule = Rule.new rule.action = rule_elm['actionTag'] rule.type = rule_elm['type'].to_sym rule.completed = rule_elm['type'] == 'true' if rule_elm['goal'] && !rule_elm['goal'].empty? rule.goal = rule_elm['goal'].to_i end challenge.rules<< rule end end challenges<< challenge end end end |
#make_get_points_balance_call(opts = {}) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/nitro_api/user_calls.rb', line 131 def make_get_points_balance_call opts={} opts = symbolize_keys opts params = { :method => 'user.getPointsBalance' } # Only include the session key when it is present. This is to make batch # calls work for this method. params[:sessionKey] = @session if @session opts_list = { criteria: 'criteria', point_category: 'pointCategory', start: 'start', end: 'end', user_id: 'userId', tags: 'tags', } opts.each do |key,value| params[opts_list[key]] = value if opts_list.has_key?(key) end make_call(params, :get) end |
#make_join_group_call(group) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/nitro_api/user_calls.rb', line 122 def make_join_group_call group params = { :sessionKey => @session, :method => 'user.joinGroup', :groupName => group } make_call(params) end |
#make_log_action_call(actions, opts = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nitro_api/user_calls.rb', line 20 def make_log_action_call actions, opts={} value = opts.delete(:value) user_id = opts.delete(:other_user) session_key = opts.delete(:session_key) params = { :tags => actions.is_a?(Array) ? actions.join(",") : actions, :method => 'user.logAction' } # Only include the session key when it is present. This is to make batch # calls work for this method. if session_key or @session params[:sessionKey] = session_key ? session_key : (@session ? @session : nil) end params[:value] = value.to_s if value && !value.to_s.empty? params[:userId] = user_id if user_id && !user_id.to_s.empty make_call(params) end |
#make_login_call ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/nitro_api/user_calls.rb', line 4 def make_login_call ts = Time.now.utc.to_i.to_s params = { :sig => sign(ts), :ts => ts, :apiKey => @api_key, :userId => @user, :method => 'user.login' } response = make_call(params) if response.is_a?(Hash) @session = response["Login"]["sessionKey"] end response end |