shopkit 0.1.0
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +46 -0
- data/LICENSE.md +20 -0
- data/README.md +19 -0
- data/Rakefile +47 -0
- data/lib/faraday_middleware/request/oauth2.rb +37 -0
- data/lib/shopkit.rb +33 -0
- data/lib/shopkit/client.rb +23 -0
- data/lib/shopkit/client/orders.rb +13 -0
- data/lib/shopkit/client/products.rb +13 -0
- data/lib/shopkit/client/shop.rb +13 -0
- data/lib/shopkit/configuration.rb +42 -0
- data/lib/shopkit/connection.rb +22 -0
- data/lib/shopkit/request.rb +40 -0
- data/lib/shopkit/version.rb +3 -0
- data/shopkit.gemspec +82 -0
- data/spec/json/orders.json +29 -0
- data/spec/json/products.json +78 -0
- data/spec/json/shop.json +25 -0
- data/spec/shopkit/client/orders_spec.rb +13 -0
- data/spec/shopkit/client/products_spec.rb +13 -0
- data/spec/shopkit/client/shop_spec.rb +13 -0
- data/spec/spec_helper.rb +26 -0
- metadata +187 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "faraday_middleware"
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "shoulda"
|
11
|
+
gem "yard"
|
12
|
+
gem "bundler"
|
13
|
+
gem "jeweler"
|
14
|
+
gem "rspec"
|
15
|
+
gem "fakeweb"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
fakeweb (1.3.0)
|
6
|
+
faraday (0.8.1)
|
7
|
+
multipart-post (~> 1.1)
|
8
|
+
faraday_middleware (0.8.7)
|
9
|
+
faraday (>= 0.7.4, < 0.9)
|
10
|
+
git (1.2.5)
|
11
|
+
jeweler (1.8.3)
|
12
|
+
bundler (~> 1.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
rdoc
|
16
|
+
json (1.7.3)
|
17
|
+
multipart-post (1.1.5)
|
18
|
+
rake (0.9.2.2)
|
19
|
+
rdoc (3.12)
|
20
|
+
json (~> 1.4)
|
21
|
+
rspec (2.10.0)
|
22
|
+
rspec-core (~> 2.10.0)
|
23
|
+
rspec-expectations (~> 2.10.0)
|
24
|
+
rspec-mocks (~> 2.10.0)
|
25
|
+
rspec-core (2.10.1)
|
26
|
+
rspec-expectations (2.10.0)
|
27
|
+
diff-lcs (~> 1.1.3)
|
28
|
+
rspec-mocks (2.10.1)
|
29
|
+
shoulda (3.0.1)
|
30
|
+
shoulda-context (~> 1.0.0)
|
31
|
+
shoulda-matchers (~> 1.0.0)
|
32
|
+
shoulda-context (1.0.0)
|
33
|
+
shoulda-matchers (1.0.0)
|
34
|
+
yard (0.8.1)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler
|
41
|
+
fakeweb
|
42
|
+
faraday_middleware
|
43
|
+
jeweler
|
44
|
+
rspec
|
45
|
+
shoulda
|
46
|
+
yard
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 saberma
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= Shopkit
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to Shopkit
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 saberma. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
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/shopkit/version.rb'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "shopkit"
|
19
|
+
gem.homepage = "http://github.com/saberma/shopkit"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = %Q{a gem for the ShopQi API}
|
22
|
+
gem.description = gem.summary
|
23
|
+
gem.email = "mahb45@gmail.com"
|
24
|
+
gem.authors = ["saberma"]
|
25
|
+
gem.version = Shopkit::VERSION
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
task :default => :spec
|
31
|
+
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new(:spec)
|
34
|
+
|
35
|
+
task :test => :spec
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
namespace :doc do
|
39
|
+
require 'yard'
|
40
|
+
YARD::Rake::YardocTask.new do |task|
|
41
|
+
task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
|
42
|
+
task.options = [
|
43
|
+
'--output-dir', 'doc/yard',
|
44
|
+
'--markup', 'markdown',
|
45
|
+
]
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
module FaradayMiddleware
|
5
|
+
# Public: A simple middleware that adds an access token to each request.
|
6
|
+
#
|
7
|
+
# The token is added "Authorization" HTTP request header.
|
8
|
+
#
|
9
|
+
# Examples
|
10
|
+
#
|
11
|
+
# # configure default token:
|
12
|
+
# OAuth2.new(app, 'abc123')
|
13
|
+
class OAuth2 < Faraday::Middleware # 不将 access_token 放在 url query
|
14
|
+
|
15
|
+
AUTH_HEADER = 'Authorization'.freeze
|
16
|
+
|
17
|
+
extend Forwardable
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
if !@token.empty?
|
21
|
+
env[:request_headers][AUTH_HEADER] ||= "Bearer #{@token}"
|
22
|
+
end
|
23
|
+
|
24
|
+
@app.call env
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(app, token = nil, options = {})
|
28
|
+
super(app)
|
29
|
+
options, token = token, nil if token.is_a? Hash
|
30
|
+
@token = token && token.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# deprecated alias
|
37
|
+
Faraday::Request::OAuth2 = FaradayMiddleware::OAuth2
|
data/lib/shopkit.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'shopkit/configuration'
|
2
|
+
require 'shopkit/client'
|
3
|
+
|
4
|
+
module Shopkit
|
5
|
+
extend Configuration
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
# @return [Shopkit::Client]
|
10
|
+
def new(options={})
|
11
|
+
options['url'] = self.url
|
12
|
+
options['access_token'] = self.access_token
|
13
|
+
Shopkit::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
# Delegate to Shopkit::Client.new
|
18
|
+
def method_missing(method, *args, &block)
|
19
|
+
return super unless new.respond_to?(method)
|
20
|
+
new.send(method, *args, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup(options)
|
24
|
+
self.url = options[:url]
|
25
|
+
self.access_token = options[:access_token]
|
26
|
+
options
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
Faraday.register_middleware :request, :oauth2 => lambda { FaradayMiddleware::OAuth2 }
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'shopkit/connection'
|
2
|
+
require 'shopkit/request'
|
3
|
+
|
4
|
+
#Load all files in client/ directory
|
5
|
+
Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/client/*.rb").sort.each do |f|
|
6
|
+
require f.match(/(shopkit\/client\/.*)\.rb$/)[0]
|
7
|
+
end
|
8
|
+
|
9
|
+
module Shopkit
|
10
|
+
class Client
|
11
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
12
|
+
|
13
|
+
def initialize(options={})
|
14
|
+
options = Shopkit.options.merge(options)
|
15
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
16
|
+
send("#{key}=", options[key])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
include Shopkit::Connection
|
21
|
+
include Shopkit::Request
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'shopkit/version'
|
3
|
+
|
4
|
+
module Shopkit
|
5
|
+
module Configuration
|
6
|
+
VALID_OPTIONS_KEYS = [
|
7
|
+
:adapter,
|
8
|
+
:api_version,
|
9
|
+
:url,
|
10
|
+
:access_token,
|
11
|
+
:user_agent,
|
12
|
+
:auto_traversal,
|
13
|
+
:per_page].freeze
|
14
|
+
|
15
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
16
|
+
DEFAULT_API_VERSION = 1
|
17
|
+
DEFAULT_USER_AGENT = "Shopkit Ruby Gem #{Shopkit::VERSION}".freeze
|
18
|
+
DEFAULT_AUTO_TRAVERSAL = false
|
19
|
+
|
20
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
21
|
+
|
22
|
+
def self.extended(base)
|
23
|
+
base.reset
|
24
|
+
end
|
25
|
+
|
26
|
+
def configure
|
27
|
+
yield self
|
28
|
+
end
|
29
|
+
|
30
|
+
def options
|
31
|
+
VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def reset
|
35
|
+
self.adapter = DEFAULT_ADAPTER
|
36
|
+
self.api_version = DEFAULT_API_VERSION
|
37
|
+
self.access_token = nil
|
38
|
+
self.user_agent = DEFAULT_USER_AGENT
|
39
|
+
self.auto_traversal = DEFAULT_AUTO_TRAVERSAL
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'faraday_middleware/request/oauth2'
|
3
|
+
|
4
|
+
module Shopkit
|
5
|
+
|
6
|
+
module Connection
|
7
|
+
private
|
8
|
+
|
9
|
+
def connection
|
10
|
+
@conn ||= Faraday.new(:url => "http://#{url}") do |builder|
|
11
|
+
builder.request :oauth2, access_token
|
12
|
+
#builder.request :json
|
13
|
+
|
14
|
+
builder.response :logger
|
15
|
+
builder.response :json, :content_type => /\bjson$/
|
16
|
+
|
17
|
+
builder.adapter :net_http
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
module Shopkit
|
4
|
+
module Request
|
5
|
+
def delete(path, options={}, version=api_version)
|
6
|
+
request(:delete, path, options, version)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(path, options={}, version=api_version)
|
10
|
+
request(:get, path, options, version)
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(path, options={}, version=api_version)
|
14
|
+
request(:post, path, options, version)
|
15
|
+
end
|
16
|
+
|
17
|
+
def put(path, options={}, version=api_version)
|
18
|
+
request(:put, path, options, version)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def request(method, path, options, version)
|
24
|
+
path = "/api#{path}" unless path.start_with?('/api')
|
25
|
+
path = "#{path}.json" unless path.end_with?('.json')
|
26
|
+
response = connection.send(method) do |request|
|
27
|
+
case method
|
28
|
+
when :delete, :get
|
29
|
+
request.url(path, options)
|
30
|
+
when :post, :put
|
31
|
+
request.path = path
|
32
|
+
request.body = options unless options.empty?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
response.body
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/shopkit.gemspec
ADDED
@@ -0,0 +1,82 @@
|
|
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
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "shopkit"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["saberma"]
|
12
|
+
s.date = "2012-06-27"
|
13
|
+
s.description = "a gem for the ShopQi API"
|
14
|
+
s.email = "mahb45@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.md",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.md",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"lib/faraday_middleware/request/oauth2.rb",
|
28
|
+
"lib/shopkit.rb",
|
29
|
+
"lib/shopkit/client.rb",
|
30
|
+
"lib/shopkit/client/orders.rb",
|
31
|
+
"lib/shopkit/client/products.rb",
|
32
|
+
"lib/shopkit/client/shop.rb",
|
33
|
+
"lib/shopkit/configuration.rb",
|
34
|
+
"lib/shopkit/connection.rb",
|
35
|
+
"lib/shopkit/request.rb",
|
36
|
+
"lib/shopkit/version.rb",
|
37
|
+
"shopkit.gemspec",
|
38
|
+
"spec/json/orders.json",
|
39
|
+
"spec/json/products.json",
|
40
|
+
"spec/json/shop.json",
|
41
|
+
"spec/shopkit/client/orders_spec.rb",
|
42
|
+
"spec/shopkit/client/products_spec.rb",
|
43
|
+
"spec/shopkit/client/shop_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = "http://github.com/saberma/shopkit"
|
47
|
+
s.licenses = ["MIT"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = "1.8.24"
|
50
|
+
s.summary = "a gem for the ShopQi API"
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<faraday_middleware>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<faraday_middleware>, [">= 0"])
|
65
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
66
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
67
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
68
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
70
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<faraday_middleware>, [">= 0"])
|
74
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
75
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
76
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
77
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
79
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"orders": [
|
3
|
+
{
|
4
|
+
"cancel_reason": null,
|
5
|
+
"cancelled_at": null,
|
6
|
+
"closed_at": "2012-05-15T21:36:38+08:00",
|
7
|
+
"created_at": "2012-04-16T23:07:33+08:00",
|
8
|
+
"customer_id": 2,
|
9
|
+
"email": "mahb45@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": 8,
|
18
|
+
"shipping_rate": "普通快递-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": "2012-05-15T21:36:38+08:00"
|
27
|
+
}
|
28
|
+
]
|
29
|
+
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
{
|
2
|
+
"products": [
|
3
|
+
{
|
4
|
+
"body_html": "",
|
5
|
+
"created_at": "2012-01-14T11:02:58+08:00",
|
6
|
+
"handle": "tee-01",
|
7
|
+
"id": 138,
|
8
|
+
"price": 45.0,
|
9
|
+
"product_type": "T恤",
|
10
|
+
"published": true,
|
11
|
+
"shop_id": 2,
|
12
|
+
"title": "Tee 01",
|
13
|
+
"updated_at": "2012-05-21T18:49:13+08:00",
|
14
|
+
"vendor": "吉尔丹",
|
15
|
+
"variants": [
|
16
|
+
{
|
17
|
+
"compare_at_price": null,
|
18
|
+
"created_at": "2012-03-26T21:45:47+08:00",
|
19
|
+
"id": 169,
|
20
|
+
"inventory_management": "",
|
21
|
+
"inventory_policy": "deny",
|
22
|
+
"inventory_quantity": null,
|
23
|
+
"option1": "默认大小",
|
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": "2012-05-21T21:24:58+08:00",
|
33
|
+
"weight": 0.0
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"compare_at_price": null,
|
37
|
+
"created_at": "2012-05-21T18:49:53+08:00",
|
38
|
+
"id": 177,
|
39
|
+
"inventory_management": "",
|
40
|
+
"inventory_policy": "deny",
|
41
|
+
"inventory_quantity": null,
|
42
|
+
"option1": "默认",
|
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": "2012-05-21T21:24:58+08:00",
|
52
|
+
"weight": 0.0
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"photos": [
|
56
|
+
{
|
57
|
+
"created_at": "2012-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": "2012-03-23T11:24:54+08:00"
|
64
|
+
}
|
65
|
+
],
|
66
|
+
"options": [
|
67
|
+
{
|
68
|
+
"name": "标题",
|
69
|
+
"position": 1
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"name": "大小",
|
73
|
+
"position": 2
|
74
|
+
}
|
75
|
+
]
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}
|
data/spec/json/shop.json
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"shop": {
|
3
|
+
"address": "",
|
4
|
+
"city": "",
|
5
|
+
"created_at": "2011-11-26T20:34:10+08:00",
|
6
|
+
"currency": "CNY",
|
7
|
+
"district": "",
|
8
|
+
"email": "admin@shopqi.com",
|
9
|
+
"domain": "shop.ruby-china.com",
|
10
|
+
"shopqi_domain": "ruby-china-shop.shopqi.com",
|
11
|
+
"id": 2,
|
12
|
+
"money_format": "¥{{amount}}",
|
13
|
+
"money_in_emails_format": "¥{{amount}}",
|
14
|
+
"money_with_currency_format": "¥{{amount}} 元",
|
15
|
+
"money_with_currency_in_emails_format": "¥{{amount}} 元",
|
16
|
+
"name": "Ruby China Shop",
|
17
|
+
"order_number_format": "#{{number}}",
|
18
|
+
"phone": "",
|
19
|
+
"plan": "unlimited",
|
20
|
+
"province": "",
|
21
|
+
"updated_at": "2012-05-24T21:34:35+08:00",
|
22
|
+
"zip_code": ""
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'fakeweb'
|
2
|
+
require 'shopkit'
|
3
|
+
|
4
|
+
FakeWeb.allow_net_connect = false
|
5
|
+
RSpec.configure do |config|
|
6
|
+
|
7
|
+
config.before(:each) do
|
8
|
+
shop_url = 'ruby-china-shop.shopqi.com'
|
9
|
+
access_token = 'b68da7c5eb6c07ff3f5a1ce731555fdc'
|
10
|
+
|
11
|
+
Shopkit.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
|
+
body = options.has_key?(:body) ? options.delete(:body) : load_json(endpoint)
|
20
|
+
method = options.delete(:method) || :get
|
21
|
+
|
22
|
+
url = "https://#{Shopkit.url}/api/#{endpoint}.json"
|
23
|
+
FakeWeb.register_uri(method, url, {:body => body, :content_type => "text/json"}.merge(options))
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shopkit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- saberma
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday_middleware
|
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: shoulda
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
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: yard
|
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
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: fakeweb
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: a gem for the ShopQi API
|
127
|
+
email: mahb45@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.md
|
132
|
+
- README.md
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- .rspec
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.md
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- lib/faraday_middleware/request/oauth2.rb
|
142
|
+
- lib/shopkit.rb
|
143
|
+
- lib/shopkit/client.rb
|
144
|
+
- lib/shopkit/client/orders.rb
|
145
|
+
- lib/shopkit/client/products.rb
|
146
|
+
- lib/shopkit/client/shop.rb
|
147
|
+
- lib/shopkit/configuration.rb
|
148
|
+
- lib/shopkit/connection.rb
|
149
|
+
- lib/shopkit/request.rb
|
150
|
+
- lib/shopkit/version.rb
|
151
|
+
- shopkit.gemspec
|
152
|
+
- spec/json/orders.json
|
153
|
+
- spec/json/products.json
|
154
|
+
- spec/json/shop.json
|
155
|
+
- spec/shopkit/client/orders_spec.rb
|
156
|
+
- spec/shopkit/client/products_spec.rb
|
157
|
+
- spec/shopkit/client/shop_spec.rb
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
homepage: http://github.com/saberma/shopkit
|
160
|
+
licenses:
|
161
|
+
- MIT
|
162
|
+
post_install_message:
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ! '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
hash: -789845379
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
none: false
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 1.8.24
|
184
|
+
signing_key:
|
185
|
+
specification_version: 3
|
186
|
+
summary: a gem for the ShopQi API
|
187
|
+
test_files: []
|