Class: SignalApi::CouponGroup

Inherits:
SignalHttpApi show all
Defined in:
lib/signal_api/coupon_group.rb

Overview

manage a copuon group using signals api

Class Method Summary collapse

Class Method Details

.consume_coupon(coupon_group_tag, mobile_phone) ⇒ Object

Consume a coupon

Parameters:

  • coupon_group_tag (String)

    The tag for the coupon group in Textme to consume this coupon from.]

  • mobile_phone (String)

    The mobile phone to consume this coupon for

Returns:

  • a coupon code



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/signal_api/coupon_group.rb', line 12

def self.consume_coupon(coupon_group_tag, mobile_phone)
  validate_consume_coupon_parameters(coupon_group_tag, mobile_phone)

  SignalApi.logger.info "Attempting to consume coupon from group #{coupon_group_tag} #{mobile_phone}"

  xml = Builder::XmlMarkup.new
  xml.request do
    xml.user do
      xml.tag!('mobile_phone',mobile_phone)
    end
    xml.tag!('coupon_group', coupon_group_tag)
  end

  with_retries do
    response = get('/api/coupon_groups/consume_coupon.xml',
                   :body => xml.target!,
                   :format => :xml,
                   :headers => common_headers)

    if response.code == 200
      response.parsed_response['coupon_code']
    else
      handle_api_failure(response)
    end
  end
end