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.



118
119
120
121
# File 'lib/uboost-client/uboost_client.rb', line 118

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



116
117
118
# File 'lib/uboost-client/uboost_client.rb', line 116

def client
  @client
end

#urlObject

Returns the value of attribute url.



116
117
118
# File 'lib/uboost-client/uboost_client.rb', line 116

def url
  @url
end

Instance Method Details

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



132
133
134
135
136
137
138
139
140
141
# File 'lib/uboost-client/uboost_client.rb', line 132

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



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

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