Module: QaddyClient

Defined in:
lib/qaddy_client.rb,
lib/qaddy_client/order.rb,
lib/qaddy_client/errors.rb,
lib/qaddy_client/helpers.rb,
lib/qaddy_client/version.rb,
lib/qaddy_client/response.rb,
lib/qaddy_client/order_item.rb,
lib/qaddy_client/configuration.rb

Defined Under Namespace

Modules: Errors, Helpers Classes: Configuration, Order, OrderItem, Response

Constant Summary collapse

VERSION =
"0.0.8"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



15
16
17
# File 'lib/qaddy_client.rb', line 15

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



22
23
24
# File 'lib/qaddy_client.rb', line 22

def self.configure
  yield(configuration) if block_given?
end

.create_url(path) ⇒ Object



26
27
28
# File 'lib/qaddy_client.rb', line 26

def self.create_url(path)
  "#{self.configuration.api_scheme}://#{self.configuration.user_id}:#{self.configuration.user_api_key}@#{self.configuration.api_host}#{self.configuration.api_prefix_path}#{path}"
end

.post_order_register(order) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/qaddy_client.rb', line 30

def self.post_order_register(order)
  url = self.create_url("/webstores/#{self.configuration.webstore_id}/orders")
  begin
    rcresponse = RestClient.post url, order.to_json, accept: 'application/json', content_type: 'application/json'
  rescue RestClient::Exception => e
    klass = case e.http_code
      when 401 then QaddyClient::Errors::Unauthorized
      when 402 then QaddyClient::Errors::VerificationRequired
      when 403 then QaddyClient::Errors::Forbidden
      when 404 then QaddyClient::Errors::NotFound
      when 408 then QaddyClient::Errors::Timeout
      when 422 then QaddyClient::Errors::RequestFailed
      when 423 then QaddyClient::Errors::Locked
      when /50./ then QaddyClient::Errors::RequestFailed
      else QaddyClient::Errors::ErrorWithResponse
    end

    qerror = klass.new(e.message, e.response)
    qerror.set_backtrace(e.backtrace)
    raise(qerror)
  end

  QaddyClient::Response.new(rcresponse)
end