Module: Shirtsio
- Defined in:
- lib/shirtsio.rb,
lib/shirtsio/json.rb,
lib/shirtsio/util.rb,
lib/shirtsio/order.rb,
lib/shirtsio/quote.rb,
lib/shirtsio/status.rb,
lib/shirtsio/product.rb,
lib/shirtsio/version.rb,
lib/shirtsio/category.rb,
lib/shirtsio/webhooks.rb,
lib/shirtsio/api_resource.rb,
lib/shirtsio/authentication.rb,
lib/shirtsio/shirtsio_object.rb,
lib/shirtsio/errors/api_error.rb,
lib/shirtsio/errors/shirtsio_error.rb,
lib/shirtsio/errors/api_connection_error.rb,
lib/shirtsio/errors/authentication_error.rb,
lib/shirtsio/errors/invalid_request_error.rb
Defined Under Namespace
Modules: JSON, Util Classes: APIConnectionError, APIError, APIResource, Authentication, AuthenticationError, Category, InvalidRequestError, Order, Product, Quote, ShirtsioError, ShirtsioObject, Status, Webhooks
Constant Summary collapse
- VERSION =
"1.0.0"
Class Attribute Summary collapse
-
.api_base ⇒ Object
Returns the value of attribute api_base.
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.api_version ⇒ Object
Returns the value of attribute api_version.
Class Method Summary collapse
Class Attribute Details
.api_base ⇒ Object
Returns the value of attribute api_base.
35 36 37 |
# File 'lib/shirtsio.rb', line 35 def api_base @api_base end |
.api_key ⇒ Object
Returns the value of attribute api_key.
35 36 37 |
# File 'lib/shirtsio.rb', line 35 def api_key @api_key end |
.api_version ⇒ Object
Returns the value of attribute api_version.
35 36 37 |
# File 'lib/shirtsio.rb', line 35 def api_version @api_version end |
Class Method Details
.api_url(url = '') ⇒ Object
38 39 40 |
# File 'lib/shirtsio.rb', line 38 def self.api_url(url='') @api_base + url end |
.request(method, url, api_key, params = {}, headers = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/shirtsio.rb', line 42 def self.request(method, url, api_key, params={}, headers={}) unless api_key ||= @api_key raise AuthenticationError.new('No API key provided. ' + 'Set your API key using "Shirtsio.api_key = <API-KEY>". ' + 'You can generate API keys from the Shirts.io web interface. ' + 'See https://www.shirts.io for details.') end if api_key =~ /\s/ raise AuthenticationError.new('Your API key is invalid, as it contains ' + 'whitespace. (HINT: You can double-check your API key from the ' + 'Shirts.io web interface. See https://www.shirts.io for details.)') end request_opts = { :verify_ssl => false } params = Util.objects_to_ids(params) params.update(:api_key => @api_key) url = api_url(url) case method.to_s.downcase.to_sym when :get, :head, :delete # Make params into GET parameters url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any? payload = nil else #payload = uri_encode(params) payload = params end request_opts.update(:method => method, :open_timeout => 30, :payload => payload, :url => url, :timeout => 80) begin #puts "in shirtsio.rb" #puts request_opts response = execute_request(request_opts) rescue SocketError => e handle_restclient_error(e) rescue NoMethodError => e # Work around RestClient bug if e. =~ /\WRequestFailed\W/ e = APIConnectionError.new('Unexpected HTTP response code') handle_restclient_error(e) else raise end rescue RestClient::ExceptionWithResponse => e if rcode = e.http_code and rbody = e.http_body handle_api_error(rcode, rbody) else handle_restclient_error(e) end rescue RestClient::Exception, Errno::ECONNREFUSED => e handle_restclient_error(e) end [parse(response), api_key] end |