Class: LinkshareAPI::CouponWebService
- Inherits:
-
Object
- Object
- LinkshareAPI::CouponWebService
- Includes:
- HTTParty
- Defined in:
- lib/linkshare_api/coupon_web_service.rb
Overview
For implementation details please visit rakutenlinkshare.zendesk.com/hc/en-us/articles/200919909-Using-the-Coupon-Web-Service
Instance Attribute Summary collapse
-
#api_base_url ⇒ Object
readonly
Returns the value of attribute api_base_url.
-
#api_timeout ⇒ Object
readonly
Returns the value of attribute api_timeout.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize ⇒ CouponWebService
constructor
A new instance of CouponWebService.
- #query(params) ⇒ Object
Constructor Details
#initialize ⇒ CouponWebService
Returns a new instance of CouponWebService.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/linkshare_api/coupon_web_service.rb', line 11 def initialize @token = LinkshareAPI.token @api_base_url = LinkshareAPI::WEB_SERVICE_URIS[:coupon_web_service] @api_timeout = LinkshareAPI.api_timeout if @token.nil? raise AuthenticationError.new( "No token. Set your token by using 'LinkshareAPI.token = <TOKEN>'. " + "You can retrieve your token from LinkhShare's Web Services page under the Links tab. " + "See https://rakutenlinkshare.zendesk.com/hc/en-us/articles/200992487-What-is-a-Web-Services-Token-Feed-Token- for details." ) end self.class.default_timeout @api_timeout end |
Instance Attribute Details
#api_base_url ⇒ Object (readonly)
Returns the value of attribute api_base_url.
9 10 11 |
# File 'lib/linkshare_api/coupon_web_service.rb', line 9 def api_base_url @api_base_url end |
#api_timeout ⇒ Object (readonly)
Returns the value of attribute api_timeout.
9 10 11 |
# File 'lib/linkshare_api/coupon_web_service.rb', line 9 def api_timeout @api_timeout end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/linkshare_api/coupon_web_service.rb', line 9 def token @token end |
Instance Method Details
#query(params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/linkshare_api/coupon_web_service.rb', line 27 def query(params) raise ArgumentError, "Hash expected, got #{params.class} instead" unless params.is_a?(Hash) params.merge!(token: token) begin response = self.class.get( api_base_url, query: params ) rescue Timeout::Error, Net::OpenTimeout raise ConnectionError.new("Timeout error (#{api_timeout}s)") end if response.code != 200 raise Error.new(response., response.code) end error = response["fault"] raise InvalidRequestError.new(error["errorstring"], error["errorcode"].to_i) if error Response.new(response, :coupon_web_service) end |