kitpay 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTMzMzFkOTllZmVlMTcwZmFmNTE1NmNhZjhkMTE5OGJkMzIyMjZlNA==
5
+ data.tar.gz: !binary |-
6
+ NjgwNmQ0ZGRhNWIzN2UxZTAwYjkzYmIzMDJkZjZiN2RhY2YyZjc2Zg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YzEyNjBmZDFkYTk4YmQ0ZWU5MGVkNWE1MzAwNjRmNjRmMmZlYzQyNTVhOTM0
10
+ NTFmZjcxNTBhNzFhMTkwNGZlZTE5NTk1MjAzNGNkMzA3YmJlNGNhOWJkYzdj
11
+ MWY2Nzc0MTJmZDRhZjAwMTZkNDhmZWFiYzcyM2M0MjE3NjJlMjk=
12
+ data.tar.gz: !binary |-
13
+ MjUyZGZmYTcyNWFhMmFhZTMxMDMwNGJlNmU3MGEyODUxNGJhNDUwNWI1N2Fi
14
+ NTIzYzdiNGQwMjc2ZmVlODhhZTg5ZTZjNzM1YWViZjM4MWRjZGNhYzg3YmNi
15
+ ZWZkZTVhYmU3YzZjMDM4ODIzNmZlZTNiYWUyODVlYjkxZTU4NWE=
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "faraday", "~> 0.8.1"
4
+ gem "faraday_middleware", "~> 0.8.8"
5
+
6
+ group :development do
7
+ gem "shoulda"
8
+ gem "yard"
9
+ gem "bundler"
10
+ gem "jeweler"
11
+ gem "rspec"
12
+ gem "webmock", "~> 1.8.7"
13
+ end
@@ -0,0 +1,51 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.8)
5
+ crack (0.3.1)
6
+ diff-lcs (1.1.3)
7
+ faraday (0.8.1)
8
+ multipart-post (~> 1.1)
9
+ faraday_middleware (0.8.8)
10
+ faraday (>= 0.7.4, < 0.9)
11
+ git (1.2.5)
12
+ jeweler (1.8.3)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ rdoc
17
+ json (1.7.3)
18
+ multipart-post (1.1.5)
19
+ rake (0.9.2.2)
20
+ rdoc (3.12)
21
+ json (~> 1.4)
22
+ rspec (2.10.0)
23
+ rspec-core (~> 2.10.0)
24
+ rspec-expectations (~> 2.10.0)
25
+ rspec-mocks (~> 2.10.0)
26
+ rspec-core (2.10.1)
27
+ rspec-expectations (2.10.0)
28
+ diff-lcs (~> 1.1.3)
29
+ rspec-mocks (2.10.1)
30
+ shoulda (3.0.1)
31
+ shoulda-context (~> 1.0.0)
32
+ shoulda-matchers (~> 1.0.0)
33
+ shoulda-context (1.0.0)
34
+ shoulda-matchers (1.0.0)
35
+ webmock (1.8.7)
36
+ addressable (>= 2.2.7)
37
+ crack (>= 0.1.7)
38
+ yard (0.8.1)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler
45
+ faraday (~> 0.8.1)
46
+ faraday_middleware (~> 0.8.8)
47
+ jeweler
48
+ rspec
49
+ shoulda
50
+ webmock (~> 1.8.7)
51
+ yard
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ # Kitpay
2
+
3
+ PayPonty Ruby API
4
+
5
+ ## Install
6
+
7
+ $ gem install kitpay
8
+
9
+ ## Use
10
+
11
+ Use api clients example:
12
+
13
+ require 'kitpay'
14
+ Kitpay.setup url: 'http://your-shop-name.myponty.com', login: 'api_key', password: 'password'
15
+ #next step
16
+ Kitpay.orders # to see yours orders
17
+
18
+ Use OAuth2 example:
19
+
20
+ require 'kitpay'
21
+ Kitpay.setup url: 'http://your-best-domain.com', access_token: 'access token'
22
+ #next step
23
+ Kitpay.products # to see yours products
24
+
25
+
26
+
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ require './lib/kitpay/version.rb'
16
+ Jeweler::Tasks.new do |gem|
17
+ gem.name = "kitpay"
18
+ gem.homepage = "http://payponty.github.io/kitpay"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Gem for the PayPonty API}
21
+ gem.description = gem.summary
22
+ gem.email = "payponty.info@gmail.com"
23
+ gem.authors = ["PayPonty"]
24
+ gem.version = Kitpay::VERSION
25
+
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ task :default => :spec
30
+
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec)
33
+
34
+ task :test => :spec
35
+ task :default => :spec
36
+
37
+ namespace :doc do
38
+ require 'yard'
39
+ YARD::Rake::YardocTask.new do |task|
40
+ task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
41
+ task.options = [
42
+ '--output-dir', 'doc/yard',
43
+ '--markup', 'markdown',
44
+ ]
45
+ end
46
+ end
@@ -0,0 +1,99 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: kitpay 0.1.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "kitpay"
9
+ s.version = "0.1.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["PayPonty"]
14
+ s.date = "2014-02-25"
15
+ s.description = "Gem for the PayPonty API"
16
+ s.email = "payponty.info@gmail.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.md",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.md",
27
+ "README.md",
28
+ "Rakefile",
29
+ "kitpay.gemspec",
30
+ "lib/faraday_middleware/request/oauth2.rb",
31
+ "lib/kitpay.rb",
32
+ "lib/kitpay/client.rb",
33
+ "lib/kitpay/client/orders.rb",
34
+ "lib/kitpay/client/products.rb",
35
+ "lib/kitpay/client/shop.rb",
36
+ "lib/kitpay/client/variants.rb",
37
+ "lib/kitpay/client/webhooks.rb",
38
+ "lib/kitpay/configuration.rb",
39
+ "lib/kitpay/connection.rb",
40
+ "lib/kitpay/request.rb",
41
+ "lib/kitpay/traversal.rb",
42
+ "lib/kitpay/version.rb",
43
+ "spec/json/order.json",
44
+ "spec/json/orders.json",
45
+ "spec/json/orders_empty.json",
46
+ "spec/json/orders_page_2.json",
47
+ "spec/json/orders_page_3.json",
48
+ "spec/json/product.json",
49
+ "spec/json/products.json",
50
+ "spec/json/shop.json",
51
+ "spec/json/variant.json",
52
+ "spec/json/webhook.json",
53
+ "spec/kitpay/client/orders_spec.rb",
54
+ "spec/kitpay/client/product_variants_spec.rb",
55
+ "spec/kitpay/client/products_spec.rb",
56
+ "spec/kitpay/client/shop_spec.rb",
57
+ "spec/kitpay/client/webhooks_spec.rb",
58
+ "spec/kitpay/kitpay_spec.rb",
59
+ "spec/spec_helper.rb"
60
+ ]
61
+ s.homepage = "http://payponty.github.io/kitpay"
62
+ s.licenses = ["MIT"]
63
+ s.rubygems_version = "2.2.2"
64
+ s.summary = "Gem for the PayPonty API"
65
+
66
+ if s.respond_to? :specification_version then
67
+ s.specification_version = 4
68
+
69
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
70
+ s.add_runtime_dependency(%q<faraday>, ["~> 0.8.1"])
71
+ s.add_runtime_dependency(%q<faraday_middleware>, ["~> 0.8.8"])
72
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
73
+ s.add_development_dependency(%q<yard>, [">= 0"])
74
+ s.add_development_dependency(%q<bundler>, [">= 0"])
75
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
76
+ s.add_development_dependency(%q<rspec>, [">= 0"])
77
+ s.add_development_dependency(%q<webmock>, ["~> 1.8.7"])
78
+ else
79
+ s.add_dependency(%q<faraday>, ["~> 0.8.1"])
80
+ s.add_dependency(%q<faraday_middleware>, ["~> 0.8.8"])
81
+ s.add_dependency(%q<shoulda>, [">= 0"])
82
+ s.add_dependency(%q<yard>, [">= 0"])
83
+ s.add_dependency(%q<bundler>, [">= 0"])
84
+ s.add_dependency(%q<jeweler>, [">= 0"])
85
+ s.add_dependency(%q<rspec>, [">= 0"])
86
+ s.add_dependency(%q<webmock>, ["~> 1.8.7"])
87
+ end
88
+ else
89
+ s.add_dependency(%q<faraday>, ["~> 0.8.1"])
90
+ s.add_dependency(%q<faraday_middleware>, ["~> 0.8.8"])
91
+ s.add_dependency(%q<shoulda>, [">= 0"])
92
+ s.add_dependency(%q<yard>, [">= 0"])
93
+ s.add_dependency(%q<bundler>, [">= 0"])
94
+ s.add_dependency(%q<jeweler>, [">= 0"])
95
+ s.add_dependency(%q<rspec>, [">= 0"])
96
+ s.add_dependency(%q<webmock>, ["~> 1.8.7"])
97
+ end
98
+ end
99
+
@@ -0,0 +1,30 @@
1
+ require 'faraday'
2
+ require 'forwardable'
3
+
4
+ module FaradayMiddleware
5
+
6
+ class OAuth2 < Faraday::Middleware
7
+
8
+ AUTH_HEADER = 'Authorization'.freeze
9
+
10
+ extend Forwardable
11
+
12
+ def call(env)
13
+ if !@token.empty?
14
+ env[:request_headers][AUTH_HEADER] ||= "Bearer #{@token}"
15
+ end
16
+
17
+ @app.call env
18
+ end
19
+
20
+ def initialize(app, token = nil, options = {})
21
+ super(app)
22
+ options, token = token, nil if token.is_a? Hash
23
+ @token = token && token.to_s
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ # deprecated alias
30
+ Faraday::Request::OAuth2 = FaradayMiddleware::OAuth2
@@ -0,0 +1,38 @@
1
+ require 'kitpay/configuration'
2
+ require 'kitpay/client'
3
+
4
+ module Kitpay
5
+ extend Configuration
6
+
7
+ class << self
8
+
9
+ # @return [Kitpay::Client]
10
+ def new(options={})
11
+ options['url'] = self.url
12
+ options['access_token'] = self.access_token
13
+ options['login'] = self.login
14
+ options['password'] = self.password
15
+ Kitpay::Client.new(options)
16
+ end
17
+
18
+
19
+ # Delegate to Kitpay::Client.new
20
+ def method_missing(method, *args, &block)
21
+ return super unless new.respond_to?(method)
22
+ new.send(method, *args, &block)
23
+ end
24
+
25
+ def setup(options)
26
+ self.url = options[:url]
27
+ self.url = "http://#{self.url}" unless self.url.start_with?('http://', 'https://')
28
+ self.access_token = options[:access_token]
29
+ self.login = options[:login] # or basic auth
30
+ self.password = options[:password]
31
+ options
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
38
+ Faraday.register_middleware :request, :oauth2 => lambda { FaradayMiddleware::OAuth2 }
@@ -0,0 +1,25 @@
1
+ require 'kitpay/connection'
2
+ require 'kitpay/request'
3
+ require 'kitpay/traversal'
4
+
5
+ #Load all files in client/ directory
6
+ Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/client/*.rb").sort.each do |f|
7
+ require f.match(/(kitpay\/client\/.*)\.rb$/)[0]
8
+ end
9
+
10
+ module Kitpay
11
+ class Client
12
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
13
+
14
+ def initialize(options={})
15
+ options = Kitpay.options.merge(options)
16
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
17
+ send("#{key}=", options[key])
18
+ end
19
+ end
20
+
21
+ include Kitpay::Connection
22
+ include Kitpay::Request
23
+ include Kitpay::Traversal
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module Kitpay
2
+ class Client
3
+ module Orders
4
+
5
+ def orders(options={})
6
+ traversal(options) do
7
+ get('/orders', options)['orders']
8
+ end
9
+ end
10
+
11
+ def order(id, options={})
12
+ get("/orders/#{id}", options)['order']
13
+ end
14
+
15
+ end
16
+
17
+ include Orders
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Kitpay
2
+ class Client
3
+ module Products
4
+
5
+ def products(options={})
6
+ traversal(options) do
7
+ get('/products', options)['products']
8
+ end
9
+ end
10
+
11
+ def product(id, options={})
12
+ get("/products/#{id}", options)['product']
13
+ end
14
+
15
+ end
16
+
17
+ include Products
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Kitpay
2
+ class Client
3
+ module Shop
4
+
5
+ def shop(options={})
6
+ get('/shop')['shop']
7
+ end
8
+
9
+ end
10
+
11
+ include Shop
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Kitpay
2
+ class Client
3
+ module Variants
4
+
5
+ def update_variant(id, options={})
6
+ put("/variants/#{id}", options)['variant']
7
+ end
8
+
9
+ end
10
+
11
+ include Variants
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Kitpay
2
+ class Client
3
+ module Webhooks
4
+
5
+ def create_webhook(options={})
6
+ post('/webhooks', options)['webhook']
7
+ end
8
+
9
+ end
10
+
11
+ include Webhooks
12
+ end
13
+ end
@@ -0,0 +1,48 @@
1
+ require 'faraday'
2
+ require 'kitpay/version'
3
+
4
+ module Kitpay
5
+ module Configuration
6
+ VALID_OPTIONS_KEYS = [
7
+ :adapter,
8
+ :api_version,
9
+ :url,
10
+ :access_token,
11
+ :login,
12
+ :password,
13
+ :user_agent,
14
+ :auto_traversal,
15
+ :per_page].freeze
16
+
17
+ DEFAULT_ADAPTER = Faraday.default_adapter
18
+ DEFAULT_API_VERSION = 1
19
+ DEFAULT_USER_AGENT = "Kitpay Ruby Gem #{Kitpay::VERSION}".freeze
20
+ DEFAULT_AUTO_TRAVERSAL = false
21
+ DEFAULT_PER_PAGE = 30
22
+
23
+ attr_accessor(*VALID_OPTIONS_KEYS)
24
+
25
+ def self.extended(base)
26
+ base.reset
27
+ end
28
+
29
+ def configure
30
+ yield self
31
+ end
32
+
33
+ def options
34
+ VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
35
+ end
36
+
37
+ def reset
38
+ self.adapter = DEFAULT_ADAPTER
39
+ self.api_version = DEFAULT_API_VERSION
40
+ self.access_token = nil
41
+ self.login = nil
42
+ self.password = nil
43
+ self.user_agent = DEFAULT_USER_AGENT
44
+ self.auto_traversal = DEFAULT_AUTO_TRAVERSAL
45
+ self.per_page = DEFAULT_PER_PAGE
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ require 'faraday_middleware'
3
+ require 'faraday_middleware/request/oauth2'
4
+
5
+ module Kitpay
6
+
7
+ module Connection
8
+ private
9
+
10
+ def connection
11
+ @conn ||= Faraday.new(:url => url) do |builder|
12
+ builder.request :oauth2, access_token if access_token
13
+ builder.request :basic_auth, login, password if login and password
14
+ builder.request :json
15
+
16
+ builder.response :json, :content_type => /\bjson$/
17
+
18
+ builder.adapter :net_http
19
+ end
20
+ @conn
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ module Kitpay
2
+ module Request
3
+ def delete(path, options={}, version=api_version)
4
+ request(:delete, path, options, version)
5
+ end
6
+
7
+ def get(path, options={}, version=api_version)
8
+ request(:get, path, options, version)
9
+ end
10
+
11
+ def post(path, options={}, version=api_version)
12
+ request(:post, path, options, version)
13
+ end
14
+
15
+ def put(path, options={}, version=api_version)
16
+ request(:put, path, options, version)
17
+ end
18
+
19
+ private
20
+
21
+ def request(method, path, options, version)
22
+ path = "/api#{path}" unless path.start_with?('/api')
23
+ path = "#{path}.json" unless path.end_with?('.json')
24
+ response = connection.send(method) do |request|
25
+ case method
26
+ when :delete, :get
27
+ request.url(path, options)
28
+ when :post, :put
29
+ request.path = path
30
+ request.body = options unless options.empty?
31
+ end
32
+ end
33
+ response.body
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ module Kitpay
2
+ module Traversal
3
+
4
+ def traversal(options)
5
+ options[:page] ||= 1
6
+ options[:per_page] ||= per_page
7
+ options[:per_page] = 100 if auto_traversal
8
+ list = yield(options) || []
9
+ if auto_traversal and !list.empty?
10
+ options[:page] += 1
11
+ list += traversal(options) do
12
+ yield(options)
13
+ end
14
+ end
15
+ list
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Kitpay
2
+ VERSION = "0.1.1" unless defined?(Kitpay::VERSION)
3
+ end
@@ -0,0 +1,27 @@
1
+ {
2
+ "order": {
3
+ "cancel_reason": null,
4
+ "cancelled_at": null,
5
+ "closed_at": "2013-05-15T21:36:38+08:00",
6
+ "created_at": "2013-04-16T23:07:33+08:00",
7
+ "customer_id": 2,
8
+ "email": "test@gmail.com",
9
+ "financial_status": "pending",
10
+ "fulfillment_status": "fulfilled",
11
+ "id": 99,
12
+ "name": "#1095",
13
+ "note": "",
14
+ "number": 95,
15
+ "order_number": 1095,
16
+ "payment_id": 1,
17
+ "shipping_rate": "test-0",
18
+ "shop_id": 2,
19
+ "status": "closed",
20
+ "subtotal_price": 45.0,
21
+ "token": "96b1d0806a03012f21f6480aa969d9a6",
22
+ "total_line_items_price": 45.0,
23
+ "total_price": 45.0,
24
+ "trade_no": null,
25
+ "updated_at": "2013-05-15T21:36:38+08:00"
26
+ }
27
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "orders": [
3
+ {
4
+ "cancel_reason": null,
5
+ "cancelled_at": null,
6
+ "closed_at": "2013-05-15T21:36:38+08:00",
7
+ "created_at": "2013-04-16T23:07:33+08:00",
8
+ "customer_id": 2,
9
+ "email": "test@gmail.com",
10
+ "financial_status": "pending",
11
+ "fulfillment_status": "fulfilled",
12
+ "id": 99,
13
+ "name": "#1095",
14
+ "note": "",
15
+ "number": 95,
16
+ "order_number": 1095,
17
+ "payment_id": 1,
18
+ "shipping_rate": "test-0",
19
+ "shop_id": 2,
20
+ "status": "closed",
21
+ "subtotal_price": 45.0,
22
+ "token": "96b1d0806a03012f21f6480aa969d9a6",
23
+ "total_line_items_price": 45.0,
24
+ "total_price": 45.0,
25
+ "trade_no": null,
26
+ "updated_at": "2013-05-15T21:36:38+08:00"
27
+ }
28
+ ]
29
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "orders": []
3
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "orders": [
3
+ {
4
+ "cancel_reason": null,
5
+ "cancelled_at": null,
6
+ "closed_at": "2013-05-15T21:36:38+08:00",
7
+ "created_at": "2013-04-16T23:07:33+08:00",
8
+ "customer_id": 2,
9
+ "email": "test@gmail.com",
10
+ "financial_status": "pending",
11
+ "fulfillment_status": "fulfilled",
12
+ "id": 100,
13
+ "name": "#1096",
14
+ "note": "",
15
+ "number": 96,
16
+ "order_number": 1096,
17
+ "payment_id": 1,
18
+ "shipping_rate": "test-0",
19
+ "shop_id": 2,
20
+ "status": "closed",
21
+ "subtotal_price": 45.0,
22
+ "token": "96b1d0806s0d928f21f6480aa969d9a6",
23
+ "total_line_items_price": 45.0,
24
+ "total_price": 45.0,
25
+ "trade_no": null,
26
+ "updated_at": "2013-05-15T21:36:38+08:00"
27
+ }
28
+ ]
29
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "orders": [
3
+ {
4
+ "cancel_reason": null,
5
+ "cancelled_at": null,
6
+ "closed_at": "2013-05-15T21:36:38+08:00",
7
+ "created_at": "2013-04-16T23:07:33+08:00",
8
+ "customer_id": 2,
9
+ "email": "test@gmail.com",
10
+ "financial_status": "pending",
11
+ "fulfillment_status": "fulfilled",
12
+ "id": 101,
13
+ "name": "#1097",
14
+ "note": "",
15
+ "number": 97,
16
+ "order_number": 1097,
17
+ "payment_id": 1,
18
+ "shipping_rate": "test-0",
19
+ "shop_id": 2,
20
+ "status": "closed",
21
+ "subtotal_price": 45.0,
22
+ "token": "96b1d0806s0d928f21f6480aa969d9a6",
23
+ "total_line_items_price": 45.0,
24
+ "total_price": 45.0,
25
+ "trade_no": null,
26
+ "updated_at": "2013-05-15T21:36:38+08:00"
27
+ }
28
+ ]
29
+ }
@@ -0,0 +1,76 @@
1
+ {
2
+ "product": {
3
+ "body_html": "",
4
+ "created_at": "2013-01-14T11:02:58+08:00",
5
+ "handle": "test-title",
6
+ "id": 138,
7
+ "price": 45.0,
8
+ "product_type": "Test type",
9
+ "published": true,
10
+ "shop_id": 2,
11
+ "title": "Test title",
12
+ "updated_at": "2013-05-21T18:49:13+08:00",
13
+ "vendor": "Test vendor",
14
+ "variants": [
15
+ {
16
+ "compare_at_price": null,
17
+ "created_at": "2013-03-26T21:45:47+08:00",
18
+ "id": 169,
19
+ "inventory_management": "",
20
+ "inventory_policy": "deny",
21
+ "inventory_quantity": null,
22
+ "option1": "Default",
23
+ "option2": "1",
24
+ "option3": "M",
25
+ "position": 1,
26
+ "price": 1900.0,
27
+ "product_id": 138,
28
+ "requires_shipping": true,
29
+ "shop_id": 2,
30
+ "sku": "",
31
+ "updated_at": "2013-05-21T21:24:58+08:00",
32
+ "weight": 0.0
33
+ },
34
+ {
35
+ "compare_at_price": null,
36
+ "created_at": "2013-05-21T18:49:53+08:00",
37
+ "id": 177,
38
+ "inventory_management": "",
39
+ "inventory_policy": "deny",
40
+ "inventory_quantity": null,
41
+ "option1": "Default2",
42
+ "option2": "3",
43
+ "option3": "XL",
44
+ "position": 2,
45
+ "price": 1900.0,
46
+ "product_id": 138,
47
+ "requires_shipping": true,
48
+ "shop_id": 2,
49
+ "sku": "",
50
+ "updated_at": "2013-05-21T21:24:58+08:00",
51
+ "weight": 0.0
52
+ }
53
+ ],
54
+ "photos": [
55
+ {
56
+ "created_at": "2013-03-23T11:24:42+08:00",
57
+ "id": 154,
58
+ "position": 0,
59
+ "product_id": 138,
60
+ "product_image_format": "jpg",
61
+ "product_image_uid": "2/products/138/pink-preview_810.jpg",
62
+ "updated_at": "2013-03-23T11:24:54+08:00"
63
+ }
64
+ ],
65
+ "options": [
66
+ {
67
+ "name": "Test1",
68
+ "position": 1
69
+ },
70
+ {
71
+ "name": "Test2",
72
+ "position": 2
73
+ }
74
+ ]
75
+ }
76
+ }
@@ -0,0 +1,78 @@
1
+ {
2
+ "products": [
3
+ {
4
+ "body_html": "",
5
+ "created_at": "2013-01-14T11:02:58+08:00",
6
+ "handle": "test-title",
7
+ "id": 138,
8
+ "price": 45.0,
9
+ "product_type": "Test type",
10
+ "published": true,
11
+ "shop_id": 2,
12
+ "title": "Test title",
13
+ "updated_at": "2013-05-21T18:49:13+08:00",
14
+ "vendor": "Test vendor",
15
+ "variants": [
16
+ {
17
+ "compare_at_price": null,
18
+ "created_at": "2013-03-26T21:45:47+08:00",
19
+ "id": 169,
20
+ "inventory_management": "",
21
+ "inventory_policy": "deny",
22
+ "inventory_quantity": null,
23
+ "option1": "Default",
24
+ "option2": "1",
25
+ "option3": "M",
26
+ "position": 1,
27
+ "price": 1900.0,
28
+ "product_id": 138,
29
+ "requires_shipping": true,
30
+ "shop_id": 2,
31
+ "sku": "",
32
+ "updated_at": "2013-05-21T21:24:58+08:00",
33
+ "weight": 0.0
34
+ },
35
+ {
36
+ "compare_at_price": null,
37
+ "created_at": "2013-05-21T18:49:53+08:00",
38
+ "id": 177,
39
+ "inventory_management": "",
40
+ "inventory_policy": "deny",
41
+ "inventory_quantity": null,
42
+ "option1": "Default2",
43
+ "option2": "3",
44
+ "option3": "XL",
45
+ "position": 2,
46
+ "price": 1900.0,
47
+ "product_id": 138,
48
+ "requires_shipping": true,
49
+ "shop_id": 2,
50
+ "sku": "",
51
+ "updated_at": "2013-05-21T21:24:58+08:00",
52
+ "weight": 0.0
53
+ }
54
+ ],
55
+ "photos": [
56
+ {
57
+ "created_at": "2013-03-23T11:24:42+08:00",
58
+ "id": 154,
59
+ "position": 0,
60
+ "product_id": 138,
61
+ "product_image_format": "jpg",
62
+ "product_image_uid": "2/products/138/pink-preview_810.jpg",
63
+ "updated_at": "2013-03-23T11:24:54+08:00"
64
+ }
65
+ ],
66
+ "options": [
67
+ {
68
+ "name": "Test1",
69
+ "position": 1
70
+ },
71
+ {
72
+ "name": "Test2",
73
+ "position": 2
74
+ }
75
+ ]
76
+ }
77
+ ]
78
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "shop": {
3
+ "address": "",
4
+ "city": "",
5
+ "created_at": "2012-11-26T20:34:10+08:00",
6
+ "currency": "USD",
7
+ "region": "",
8
+ "email": "admin@shopqi.com",
9
+ "domain": "shop.ruby-china.com",
10
+ "shopqi_domain": "test-store.myponty.com",
11
+ "id": 2,
12
+ "money_format": "${{amount}}",
13
+ "money_in_emails_format": "${{amount}}",
14
+ "money_with_currency_format": "$ {{amount}} USD",
15
+ "money_with_currency_in_emails_format": "${{amount}} USD",
16
+ "name": "Test Store",
17
+ "order_number_format": "#{{number}}",
18
+ "phone": "",
19
+ "plan": "unlimited",
20
+ "country": "",
21
+ "updated_at": "2013-05-24T21:34:35+08:00",
22
+ "zip_code": ""
23
+ }
24
+ }
25
+
@@ -0,0 +1,21 @@
1
+ {
2
+ "variant":
3
+ {
4
+ "id": 1,
5
+ "product_id": 1,
6
+ "price": 45,
7
+ "compare_at_price": 69,
8
+ "weight": 2.9,
9
+ "sku": "test001",
10
+ "position": 1,
11
+ "option1": "Default",
12
+ "option2": null,
13
+ "option3": null,
14
+ "requires_shipping": true,
15
+ "inventory_quantity": 0,
16
+ "inventory_management": "fwm",
17
+ "inventory_policy": "deny",
18
+ "created_at": "2013-04-16T23:07:33+08:00",
19
+ "update_at": "2013-04-16T23:07:33+08:00"
20
+ }
21
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "webhook":
3
+ {
4
+ "id": 1,
5
+ "event": "order/fulfilled",
6
+ "callback_url": "http://lvh.me/webhook"
7
+ }
8
+ }
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kitpay::Client::Orders do
4
+
5
+ it 'should get orders' do
6
+ fake_web "orders", query: {per_page: 30, page: 1}
7
+ Kitpay.orders.size.should_not eql 0
8
+ end
9
+
10
+ it 'should get order' do
11
+ id = 99
12
+ fake_web "orders/#{id}", json_file: :order
13
+ Kitpay.order(id)['id'].should eql id
14
+ end
15
+
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kitpay::Client::Products do
4
+
5
+ let(:id) { 1 }
6
+
7
+ let(:body) { { variant: { id: id, price: 45 } } }
8
+
9
+ before do
10
+ fake_web "variants/#{id}", method: :put, request_body: body.to_json, json_file: :variant
11
+ end
12
+
13
+ it 'should update variant' do
14
+ variant = Kitpay.update_variant(id, body)
15
+ variant['price'].should eql 45
16
+ end
17
+
18
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kitpay::Client::Products do
4
+
5
+ before do
6
+ fake_web "products", query: {per_page: 30, page: 1}
7
+ end
8
+
9
+ it 'should get products' do
10
+ Kitpay.products.size.should_not eql 0
11
+ end
12
+
13
+ it 'should get product' do
14
+ id = 138
15
+ fake_web "products/#{id}", json_file: :product
16
+ Kitpay.product(id)['id'].should eql id
17
+ end
18
+
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kitpay::Client::Shop do
4
+
5
+ before do
6
+ fake_web "shop"
7
+ end
8
+
9
+ it 'should get current shop' do
10
+ Kitpay.shop['domain'].should_not be_empty
11
+ end
12
+
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kitpay::Client::Webhooks do
4
+
5
+ let(:request_body) { { webhook: { event: "order/fulfilled", callback_url: "http://lvh.me/webhook" }}.to_json }
6
+
7
+ before do
8
+ fake_web 'webhooks', method: :post, request_body: request_body, json_file: :webhook
9
+ end
10
+
11
+ it 'should be create' do
12
+ webhook = Kitpay.create_webhook(webhook: {event: 'order/fulfilled', callback_url: 'http://lvh.me/webhook'})
13
+ webhook['id'].should_not be_nil
14
+ end
15
+
16
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kitpay do
4
+
5
+ context 'with permission' do
6
+
7
+ before do
8
+ Kitpay.auto_traversal = true
9
+ fake_web "orders", query: {per_page: 100, page: 1}
10
+ fake_web "orders", query: {per_page: 100, page: 2}, json_file: "orders_page_2"
11
+ fake_web "orders", query: {per_page: 100, page: 3}, json_file: "orders_page_3"
12
+ fake_web "orders", query: {per_page: 100, page: 4}, json_file: "orders_empty"
13
+ end
14
+
15
+ after do
16
+ Kitpay.auto_traversal = false
17
+ end
18
+
19
+ it 'should be auto_traversal' do
20
+ Kitpay.orders(page: 1).size.should eql 3
21
+ end
22
+
23
+ end
24
+
25
+ context 'without permission' do
26
+
27
+ describe 'list' do
28
+
29
+ it 'should not be nil' do
30
+ stub_request(:get, "#{Kitpay.url}/api/orders.json?page=1&per_page=30").to_return(status: 401, body: "")
31
+ Kitpay.orders.should eql []
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+ require 'kitpay'
3
+ require 'webmock/rspec'
4
+
5
+ RSpec.configure do |config|
6
+
7
+ config.before(:each) do
8
+ shop_url = 'http://test-store.myponty.com'
9
+ access_token = 'b68da7c5eb6c07ff3f5a1ce731555fdc'
10
+
11
+ Kitpay.setup(url: shop_url, access_token: access_token)
12
+ end
13
+
14
+ def load_json(name)
15
+ File.read(File.dirname(__FILE__) + "/json/#{name}.json")
16
+ end
17
+
18
+ def fake_web(endpoint, options={})
19
+ file = options[:json_file] || endpoint
20
+ request_body = options.delete(:request_body)
21
+ body = options.has_key?(:body) ? options.delete(:body) : load_json(file)
22
+ method = options.delete(:method) || :get
23
+
24
+ url = "#{Kitpay.url}/api/#{endpoint}.json"
25
+ params = {body: request_body}
26
+ params.merge! query: options[:query] if options[:query]
27
+ stub_request(method, url).with(params).to_return(body: body, headers: { content_type: 'text/json' })
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - PayPonty
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: shoulda
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.8.7
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 1.8.7
125
+ description: Gem for the PayPonty API
126
+ email: payponty.info@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files:
130
+ - LICENSE.md
131
+ - README.md
132
+ files:
133
+ - .document
134
+ - .rspec
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE.md
138
+ - README.md
139
+ - Rakefile
140
+ - kitpay.gemspec
141
+ - lib/faraday_middleware/request/oauth2.rb
142
+ - lib/kitpay.rb
143
+ - lib/kitpay/client.rb
144
+ - lib/kitpay/client/orders.rb
145
+ - lib/kitpay/client/products.rb
146
+ - lib/kitpay/client/shop.rb
147
+ - lib/kitpay/client/variants.rb
148
+ - lib/kitpay/client/webhooks.rb
149
+ - lib/kitpay/configuration.rb
150
+ - lib/kitpay/connection.rb
151
+ - lib/kitpay/request.rb
152
+ - lib/kitpay/traversal.rb
153
+ - lib/kitpay/version.rb
154
+ - spec/json/order.json
155
+ - spec/json/orders.json
156
+ - spec/json/orders_empty.json
157
+ - spec/json/orders_page_2.json
158
+ - spec/json/orders_page_3.json
159
+ - spec/json/product.json
160
+ - spec/json/products.json
161
+ - spec/json/shop.json
162
+ - spec/json/variant.json
163
+ - spec/json/webhook.json
164
+ - spec/kitpay/client/orders_spec.rb
165
+ - spec/kitpay/client/product_variants_spec.rb
166
+ - spec/kitpay/client/products_spec.rb
167
+ - spec/kitpay/client/shop_spec.rb
168
+ - spec/kitpay/client/webhooks_spec.rb
169
+ - spec/kitpay/kitpay_spec.rb
170
+ - spec/spec_helper.rb
171
+ homepage: http://payponty.github.io/kitpay
172
+ licenses:
173
+ - MIT
174
+ metadata: {}
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ! '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ! '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ requirements: []
190
+ rubyforge_project:
191
+ rubygems_version: 2.2.2
192
+ signing_key:
193
+ specification_version: 4
194
+ summary: Gem for the PayPonty API
195
+ test_files: []
196
+ has_rdoc: