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 helpcenter.linkshare.com/publisher/questions.php?questionid=865
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.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/linkshare_api/coupon_web_service.rb', line 12 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 http://helpcenter.linkshare.com/publisher/questions.php?questionid=648 for details." ) end end |
Instance Attribute Details
#api_base_url ⇒ Object (readonly)
Returns the value of attribute api_base_url.
10 11 12 |
# File 'lib/linkshare_api/coupon_web_service.rb', line 10 def api_base_url @api_base_url end |
#api_timeout ⇒ Object (readonly)
Returns the value of attribute api_timeout.
10 11 12 |
# File 'lib/linkshare_api/coupon_web_service.rb', line 10 def api_timeout @api_timeout end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
10 11 12 |
# File 'lib/linkshare_api/coupon_web_service.rb', line 10 def token @token end |
Instance Method Details
#query(params) ⇒ Object
26 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 26 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, timeout: api_timeout ) rescue Timeout::Error raise ConnectionError.new("Timeout error (#{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 |