Class: HitfoxCouponApi::User

Inherits:
Client
  • Object
show all
Defined in:
lib/hitfox_coupon_api/user.rb

Constant Summary

Constants inherited from Client

Client::HitfoxApiException

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#apiheaders, #configuration, #generate_url, #handle_coupon_results

Constructor Details

#initialize(application, user_id) ⇒ User

Returns a new instance of User.



5
6
7
# File 'lib/hitfox_coupon_api/user.rb', line 5

def initialize(application, user_id)
  @application, @user_id = application, user_id
end

Instance Attribute Details

#user_idObject

Returns the value of attribute user_id.



3
4
5
# File 'lib/hitfox_coupon_api/user.rb', line 3

def user_id
  @user_id
end

Instance Method Details

#buy_coupon(count = 1) ⇒ Object

buy count coupons for this application. If there aren’t enough coupons, then this will return an empty list. This is an all-or-nothing call, if count coupons aren’t available, then none are bought.



12
13
14
15
16
# File 'lib/hitfox_coupon_api/user.rb', line 12

def buy_coupon(count = 1)
  headers, params = build_request_data
  urlstr = generate_url('/%s/coupon/%s/buy.json?hash=%s&count=%s', params + [count.to_s])
  handle_coupon_results(JSON.parse(RestClient.get(urlstr, headers)))
end

#couponsObject

Get a list coupons for this user, for this application.



19
20
21
22
23
# File 'lib/hitfox_coupon_api/user.rb', line 19

def coupons
  headers, params = build_request_data
  urlstr = generate_url('/%s/coupon/%s/show.json?hash=%s', params)
  handle_coupon_results(JSON.parse(RestClient.get(urlstr, headers)))
end