qaddy-client 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ todo.txt
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qaddy_client.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Zoran Mijatovic
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # QaddyClient
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'qaddy-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install qaddy-client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,55 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+ require 'json'
4
+ require 'rest_client'
5
+ require "qaddy_client/version"
6
+ require "qaddy_client/configuration"
7
+ require "qaddy_client/helpers"
8
+ require "qaddy_client/errors"
9
+ require "qaddy_client/response"
10
+ require "qaddy_client/order"
11
+ require "qaddy_client/order_item"
12
+
13
+ module QaddyClient
14
+ class << self
15
+ attr_accessor :configuration
16
+ end
17
+
18
+ def self.configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ def self.configure
23
+ yield(configuration) if block_given?
24
+ end
25
+
26
+ def self.create_url(path)
27
+ "#{self.configuration.api_scheme}://#{self.configuration.user_id}:#{self.configuration.user_api_key}@#{self.configuration.api_host}#{self.configuration.api_prefix_path}#{path}"
28
+ end
29
+
30
+ def self.post_order_register(order)
31
+ url = self.create_url("/webstores/#{self.configuration.webstore_id}/orders")
32
+ begin
33
+ rcresponse = RestClient.post url, order.to_json, accept: 'application/json', content_type: 'application/json'
34
+ rescue RestClient::Exception => e
35
+ klass = case e.http_code
36
+ when 401 then QaddyClient::Errors::Unauthorized
37
+ when 402 then QaddyClient::Errors::VerificationRequired
38
+ when 403 then QaddyClient::Errors::Forbidden
39
+ when 404 then QaddyClient::Errors::NotFound
40
+ when 408 then QaddyClient::Errors::Timeout
41
+ when 422 then QaddyClient::Errors::RequestFailed
42
+ when 423 then QaddyClient::Errors::Locked
43
+ when /50./ then QaddyClient::Errors::RequestFailed
44
+ else QaddyClient::Errors::ErrorWithResponse
45
+ end
46
+
47
+ qerror = klass.new(e.message, e.response)
48
+ qerror.set_backtrace(e.backtrace)
49
+ raise(qerror)
50
+ end
51
+
52
+ QaddyClient::Response.new(rcresponse)
53
+ end
54
+
55
+ end
@@ -0,0 +1,21 @@
1
+ module QaddyClient
2
+ class Configuration
3
+ attr_accessor :api_host,
4
+ :api_scheme,
5
+ :user_id,
6
+ :user_api_key,
7
+ :webstore_id
8
+
9
+ attr_reader :api_prefix_path
10
+
11
+ def initialize
12
+ self.api_host = nil
13
+ self.api_scheme = nil
14
+ self.user_id = nil
15
+ self.user_api_key = nil
16
+ self.webstore_id = nil
17
+
18
+ @api_prefix_path = '/api/v1'
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ module QaddyClient
2
+ module Errors
3
+ class Error < StandardError; end
4
+
5
+ class ErrorWithResponse < Error
6
+ attr_reader :response
7
+ attr_reader :code
8
+ attr_reader :result
9
+
10
+ def initialize(message, response)
11
+ super message
12
+ @response = response
13
+ @code = response.code
14
+ @result = response.body
15
+
16
+ begin
17
+ @result = JSON.parse(@result)
18
+ rescue
19
+ # leave non-JSON body as is
20
+ end
21
+ end
22
+ end
23
+
24
+ class Unauthorized < ErrorWithResponse; end
25
+ class VerificationRequired < ErrorWithResponse; end
26
+ class Forbidden < ErrorWithResponse; end
27
+ class NotFound < ErrorWithResponse; end
28
+ class Timeout < ErrorWithResponse; end
29
+ class Locked < ErrorWithResponse; end
30
+ class RequestFailed < ErrorWithResponse; end
31
+
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ module QaddyClient
2
+ module Helpers
3
+
4
+ def instance_variables_to_hash
5
+ h = {}
6
+ instance_variables.each do |e|
7
+ o = instance_variable_get e.to_sym
8
+ h[e[1..-1]] = (o.respond_to? :instance_variables_to_hash) ? o.instance_variables_to_hash : o;
9
+ end
10
+ h
11
+ end
12
+
13
+ def to_json *a
14
+ instance_variables_to_hash.to_json *a
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ module QaddyClient
2
+ class Order
3
+ include QaddyClient::Helpers
4
+
5
+ attr_reader :customer_email
6
+ attr_reader :customer_name
7
+ attr_reader :discount_code_perc
8
+ attr_reader :number
9
+ attr_reader :send_email_after_hours
10
+ attr_reader :send_email_at
11
+ attr_reader :total
12
+
13
+ attr_reader :order_items_attributes
14
+
15
+ def initialize(attributes)
16
+ @customer_email = attributes[:customer_email]
17
+ @customer_name = attributes[:customer_name]
18
+ @discount_code_perc = attributes[:discount_code_perc]
19
+ @number = attributes[:number]
20
+ @send_email_after_hours = attributes[:send_email_after_hours]
21
+ @send_email_at = attributes[:send_email_at]
22
+ @total = attributes[:total]
23
+
24
+ @order_items_attributes = Array.new
25
+ end
26
+
27
+ def add_item(order)
28
+ @order_items_attributes.push(order)
29
+ end
30
+
31
+ def post
32
+ puts "Posting order..."
33
+ QaddyClient.configuration
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ module QaddyClient
2
+ class OrderItem
3
+ include QaddyClient::Helpers
4
+
5
+ attr_reader :default_sharing_text
6
+ attr_reader :description
7
+ attr_reader :image_url
8
+ attr_reader :name
9
+ attr_reader :page_url
10
+ attr_reader :qty
11
+ attr_reader :total
12
+
13
+ def initialize(attributes)
14
+ @default_sharing_text = attributes[:default_sharing_text]
15
+ @description = attributes[:description]
16
+ @image_url = attributes[:image_url]
17
+ @name = attributes[:name]
18
+ @page_url = attributes[:page_url]
19
+ @qty = attributes[:qty]
20
+ @total = attributes[:total]
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ module QaddyClient
2
+ class Response
3
+ attr_reader :code
4
+ attr_reader :description
5
+ attr_reader :result
6
+ attr_reader :response
7
+
8
+ def initialize(restclient_response)
9
+ @response = restclient_response
10
+ @code = restclient_response.code
11
+ @description = restclient_response.description
12
+
13
+ if restclient_response.body && !restclient_response.body.empty?
14
+ @result = restclient_response.body
15
+ else
16
+ @result = ""
17
+ end
18
+
19
+ begin
20
+ @result = JSON.parse(@result)
21
+ rescue
22
+ # leave non-JSON body as is
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module QaddyClient
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/qaddy_client/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "qaddy-client"
6
+ gem.version = QaddyClient::VERSION
7
+
8
+ gem.authors = ["Zoran Mijatovic"]
9
+ gem.email = ["zmijatovic@alturabit.com"]
10
+ gem.description = %q{Qaddy API client}
11
+ gem.summary = %q{Qaddy API client}
12
+ gem.homepage = ""
13
+
14
+ gem.files = `git ls-files`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency "json"
20
+ gem.add_dependency "rest-client"
21
+
22
+ gem.add_development_dependency "rspec"
23
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qaddy-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zoran Mijatovic
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Qaddy API client
63
+ email:
64
+ - zmijatovic@alturabit.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - lib/qaddy_client.rb
75
+ - lib/qaddy_client/configuration.rb
76
+ - lib/qaddy_client/errors.rb
77
+ - lib/qaddy_client/helpers.rb
78
+ - lib/qaddy_client/order.rb
79
+ - lib/qaddy_client/order_item.rb
80
+ - lib/qaddy_client/response.rb
81
+ - lib/qaddy_client/version.rb
82
+ - qaddy-client.gemspec
83
+ homepage: ''
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.24
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Qaddy API client
107
+ test_files: []