Class: Warbler::RewardsController

Inherits:
ApplicationController show all
Defined in:
lib/warbler/controllers/rewards_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#initialize

Constructor Details

This class inherits a constructor from Warbler::ApplicationController

Instance Method Details

#bid(amount, id) ⇒ Object

Bid on a reward auction.

Parameters:

  • amount (String)

    Required parameter: Can be either ‘max’ (when max bidding) or the number of points the user wants to bid.

  • id (Numeric)

    Required parameter: Id of the reward

Returns:

  • mixed response from the API call



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/warbler/controllers/rewards_controller.rb', line 32

def bid amount, id
  # the base uri for api requests
  query_builder = base_uri

  # prepare query string for API call
  query_builder << "/v3/rewards/#{ id }/bids"

  # process optional query parameters
  query_builder = APIHelper.append_url_with_template_parameters query_builder, {
    "id" => id,
    "amount" => amount
  }

  perform_query('post', query_builder)
end

#list(category_id: nil, limit: 25, offset: 0) ⇒ Object

List all the available rewards.

Parameters:

  • category_id (Numeric) (defaults to: nil)

    Optional parameter: The id of the category to filter rewards by

  • limit (Numeric) (defaults to: 25)

    Optional parameter: The number of rewards you want to be retrieved.

  • offset (Numeric) (defaults to: 0)

    Optional parameter: The number of rewards you want to skip before starting the retrieval.

Returns:

  • mixed response from the API call



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/warbler/controllers/rewards_controller.rb', line 11

def list category_id: nil, limit: 25, offset: 0
  # the base uri for api requests
  query_builder = base_uri

  # prepare query string for API call
  query_builder << "/v3/rewards"

  # process optional query parameters
  query_builder = APIHelper.append_url_with_query_parameters query_builder, {
    "category_id" => category_id,
    "limit" => if limit.nil? then 25 else limit end,
    "offset" => if offset.nil? then 0 else offset end,
  }

  perform_query('get', query_builder)
end

#redeem(id) ⇒ Object

Redeem a reward.

Parameters:

  • id (Numeric)

    Required parameter: Id of the reward

Returns:

  • mixed response from the API call



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/warbler/controllers/rewards_controller.rb', line 69

def redeem id
  # the base uri for api requests
  query_builder = base_uri

  # prepare query string for API call
  query_builder << "/v3/rewards/#{ id }/redemptions"

  # process optional query parameters
  query_builder = APIHelper.append_url_with_template_parameters query_builder, {
    "id" => id,
  }

  perform_query('post', query_builder)
end

#show(id) ⇒ Object

Show a reward’s details.

Parameters:

  • id (Numeric)

    Required parameter: Id of the reward

Returns:

  • mixed response from the API call



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/warbler/controllers/rewards_controller.rb', line 51

def show id
  # the base uri for api requests
  query_builder = base_uri

  # prepare query string for API call
  query_builder << "/v3/rewards/#{ id }"

  # process optional query parameters
  query_builder = APIHelper.append_url_with_template_parameters query_builder, {
    "id" => id,
  }

  perform_query('get', query_builder)
end