Class: UboostClient::Points

Inherits:
Object
  • Object
show all
Defined in:
lib/uboost-client/uboost_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Points

Returns a new instance of Points.



123
124
125
126
# File 'lib/uboost-client/uboost_client.rb', line 123

def initialize(client)
  @client = client
  @url = '/api/points_transactions'
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



121
122
123
# File 'lib/uboost-client/uboost_client.rb', line 121

def client
  @client
end

#urlObject

Returns the value of attribute url.



121
122
123
# File 'lib/uboost-client/uboost_client.rb', line 121

def url
  @url
end

Instance Method Details

#add_points_to_account(id, points, options = nil) ⇒ Object



137
138
139
140
141
142
143
144
145
146
# File 'lib/uboost-client/uboost_client.rb', line 137

def (id, points, options = nil)
  data = {:points_transaction => {:account_id => id, :points_change => points}}
  data[:points_transaction].merge!(options) if options
  response = client.connection.post do |req|
    req.url @url
    req.headers['Content-Type'] = 'application/json'
    req.body = JSON.generate(data)
  end
  OpenStruct.new(JSON.parse(response.body))
end

#points_transactions_for_account(id_or_options) ⇒ Object



128
129
130
131
132
133
134
135
# File 'lib/uboost-client/uboost_client.rb', line 128

def (id_or_options)
  options = id_or_options
  options = {:account_id => id_or_options} if !id_or_options.is_a? Hash
  response = client.connection.get do |req|
    req.url @url, options
  end
  OpenStruct.new(JSON.parse(response.body))
end