Class: NitroApi::NitroApi

Inherits:
Object
  • Object
show all
Includes:
BatchCalls, SiteCalls, UserCalls
Defined in:
lib/nitro_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UserCalls

#make_action_history_call, #make_award_challenge_call, #make_challenge_progress_call, #make_get_points_balance_call, #make_join_group_call, #make_log_action_call, #make_login_call

Methods included from SiteCalls

#make_points_leaders_call

Constructor Details

#initialize(user_id, api_key, secret) ⇒ NitroApi

Initialize an instance user_id - The id for the user in the nitro system api_key - The API key for your Bunchball account secret - The secret for your Bunchball account



32
33
34
35
36
37
38
39
40
41
# File 'lib/nitro_api.rb', line 32

def initialize (user_id, api_key, secret)
  @secret = secret
  @api_key = api_key
  @user = user_id
  @batch = nil

  self.protocol = 'https'
  self.host = 'sandbox.bunchball.net'
  self.accepts = 'json'
end

Instance Attribute Details

#acceptsObject

Returns the value of attribute accepts.



26
27
28
# File 'lib/nitro_api.rb', line 26

def accepts
  @accepts
end

#hostObject

Returns the value of attribute host.



26
27
28
# File 'lib/nitro_api.rb', line 26

def host
  @host
end

#protocolObject

Returns the value of attribute protocol.



26
27
28
# File 'lib/nitro_api.rb', line 26

def protocol
  @protocol
end

#sessionObject

Returns the value of attribute session.



26
27
28
# File 'lib/nitro_api.rb', line 26

def session
  @session
end

Instance Method Details

#action_history(actions = []) ⇒ Object



105
106
107
# File 'lib/nitro_api.rb', line 105

def action_history actions=[]
  make_action_history_call actions
end

#award_challenge(challenge) ⇒ Object



101
102
103
# File 'lib/nitro_api.rb', line 101

def award_challenge challenge
  make_award_challenge_call challenge
end

#base_urlObject



131
132
133
# File 'lib/nitro_api.rb', line 131

def base_url
  "#{self.protocol}://#{self.host}#{base_url_path}"
end

#base_url_pathObject



135
136
137
# File 'lib/nitro_api.rb', line 135

def base_url_path
  "/nitro/#{self.accepts}"
end

#cancel_batchObject

Cancel the batch job. It clears out the any accumulated calls that have been made since first calling start_batch



71
72
73
# File 'lib/nitro_api.rb', line 71

def cancel_batch
  @batch = nil
end

#challenge_progress(opts = {}) ⇒ Object



97
98
99
# File 'lib/nitro_api.rb', line 97

def challenge_progress opts={}
  make_challenge_progress_call opts
end

#get_points_balance(opts = {}) ⇒ Object

Get the points for a user.

Parameters:



118
119
120
# File 'lib/nitro_api.rb', line 118

def get_points_balance opts={}
  make_get_points_balance_call opts
end

#get_points_leaders(opts) ⇒ Object

Get the list of point leaders for the specified options. opts - The list of options. The keys in the list are the snake_case

versions names of the parameters to the getPointsLeaders API call
as defined here:
https://bunchballnet-main.pbworks.com/w/page/53132408/site_getPointsLeaders


127
128
129
# File 'lib/nitro_api.rb', line 127

def get_points_leaders opts
  make_points_leaders_call opts
end

#join_group(group) ⇒ Object



109
110
111
# File 'lib/nitro_api.rb', line 109

def join_group group
  make_join_group_call group
end

#log_action(actions, opts = {}) ⇒ Object

Log actions to the nitro system

Parameters:

  • actions (String, Array[String])

    The (list of) action tag(s) to log

  • opts (Hash) (defaults to: {})

    The options. They are: :value - the value to send :other_user - the ID of the user to which the action should be applied :session_key - the session key to use for this call



93
94
95
# File 'lib/nitro_api.rb', line 93

def log_action actions, opts={}
  make_log_action_call actions, opts
end

#loginObject

Login the user to the nitro system



83
84
85
# File 'lib/nitro_api.rb', line 83

def 
  
end

#run_batchObject

Run the batch job. Requires that the ‘start_batch’ method has been called first.



65
66
67
# File 'lib/nitro_api.rb', line 65

def run_batch
  make_run_batch_call
end

#sign(time) ⇒ Object

Method for constructing a signature



76
77
78
79
80
# File 'lib/nitro_api.rb', line 76

def sign(time)
  unencrypted_signature = @api_key + @secret + time + @user.to_s
  to_digest = unencrypted_signature + unencrypted_signature.length.to_s
  return Digest::MD5.hexdigest(to_digest)
end

#start_batchObject

Start a batch call to the nitro API. Uses the “batch.run” method defined here: bunchballnet-main.pbworks.com/w/page/53132313/batch_run returns - false if a batch is already being composed, true otherwise



46
47
48
49
50
51
52
53
# File 'lib/nitro_api.rb', line 46

def start_batch
  if @batch.nil?
    @batch = []
    return true
  end

  return false
end

#start_batch!Object

Start a batch call to the nitro API. Uses the “batch.run” method defined here: bunchballnet-main.pbworks.com/w/page/53132313/batch_run If a batch is already being composed, an error will be raised.



58
59
60
61
62
# File 'lib/nitro_api.rb', line 58

def start_batch!
  if not start_batch
    raise NitroError.new, "A batch is already being composed."
  end
end