weidian_open 0.0.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d26403dc761ac63a39007d05797ef547db05ed19
4
+ data.tar.gz: edcdea3e7a0ad3c68a703fc0ec2abdd6615018d7
5
+ SHA512:
6
+ metadata.gz: 3244aaf2fbeebf5ce2b40e98efc4624b44977ff55e35e55346b0ea273db011908bdded3425b4eb26841b35240795965e685b650e59158c91e47af02d1448e931
7
+ data.tar.gz: 916054588e7735874409c6488d289800c4f4430201cd51e23613719c327d84f76fd86ab9e2ed038b40509676de7e43d1e9ee77d73593a3911c2a75f672f8704b
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://ruby.taobao.org'
2
+
3
+ group :development do
4
+ gem 'pry'
5
+ end
6
+
7
+ gem 'eat'
8
+
9
+ # Specify your gem's dependencies in weidian.gemspec
10
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Yanying Wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 YanyingWang
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,74 @@
1
+ WeidianOpen
2
+ =========
3
+ [Weidian Open Platform(微店开放平台)](http://open.weidian.com/) API in Ruby
4
+
5
+ ## Installation
6
+ Add this line to your application's Gemfile:
7
+ ```ruby
8
+ gem 'weidian_open'
9
+ ```
10
+
11
+ And then execute:
12
+ ```shell
13
+ $ bundle
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```shell
18
+ $ gem install weidian_open
19
+ ```
20
+
21
+ ## Usage
22
+ #### Information about this gem:
23
+ ```ruby
24
+ puts WeidianOpen::API
25
+ puts WeidianOpen::HOWTO_CONFIG
26
+ ```
27
+
28
+ #### Configuration
29
+ ```ruby
30
+ WeidianOpen.config do
31
+ @app_key = '1111111' # your app_key
32
+ @app_secret = '1111111111111111' # your app_secret
33
+ end
34
+ ```
35
+ or
36
+ ```ruby
37
+ WeidianOpen.app_key = '111111' # your app_key
38
+ WeidianOpen.app_secret = '1111111111' # your app_secret
39
+ ```
40
+
41
+ ###Access Token
42
+ Access Token can be refreshed automatically by this Gem.
43
+ You can show access token used currently after configuration:
44
+ ```ruby
45
+ WeidianOpen.access_token
46
+ ```
47
+
48
+ #### [Weidian Open API WIKI](http://wiki.open.weidian.com/):
49
+ Normally, you can use any Offical API method if HTTP Method of it is GET.
50
+ All you need to do is subsituing "." inside API method name with "_".
51
+
52
+ Example:
53
+ * API method: [vdian.order.list.get](http://wiki.open.weidian.com/index.php?title=%E8%8E%B7%E5%8F%96%E8%AE%A2%E5%8D%95%E5%88%97%E8%A1%A8)
54
+ ```ruby
55
+ WeidianOpen.vdian_order_list_get(page_num: "1",
56
+ order_type: "unpay",
57
+ add_start: "2015-03-18 14:15:12",
58
+ add_end: "2015-03-20 14:15:12")
59
+
60
+ WeidianOpen.vdian_order_list_get(order_type: "unpay", page_num: "1")
61
+ ```
62
+
63
+ * API method: [vdian.order.get](http://wiki.open.weidian.com/index.php?title=%E8%8E%B7%E5%8F%96%E8%AE%A2%E5%8D%95%E5%88%97%E8%A1%A8)
64
+ ```ruby
65
+ WeidianOpen.vdian_order_get(order_id: "1164787976")
66
+ ```
67
+
68
+ ## Contributing
69
+ 1. Fork it ( https://github.com/yanyingwang/weidian_open/fork )
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create a new Pull Request
74
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module WeidianOpen
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,67 @@
1
+ require "weidian_open/version"
2
+ require 'eat'
3
+ require 'json'
4
+
5
+ module WeidianOpen
6
+ API = { endpoint: 'https://api.vdian.com',
7
+ version: '1.0',
8
+ format: 'json' }
9
+
10
+ HOWTO_CONFIG = <<-EOF
11
+ #{self.name}.config do
12
+ @app_key = '1111111' # your app_key
13
+ @app_secret = '1111111111111111' # your app_secret
14
+ end
15
+
16
+ or:
17
+
18
+ #{self.name}.app_key = '111111' # your app_key
19
+ #{self.name}.app_secret = '1111111111' # your app_secret
20
+ EOF
21
+
22
+
23
+ class << self
24
+
25
+ alias_method :config, :instance_eval
26
+ attr_accessor :app_key, :app_secret
27
+
28
+ def access_token
29
+ (@access_token && !access_token_expired?) ? @access_token : get_access_token_from_api
30
+ end
31
+
32
+
33
+ private
34
+
35
+ def method_missing(method, **param)
36
+ public = { method: method.to_s.gsub('_', '.'),
37
+ access_token: access_token,
38
+ version: API[:version],
39
+ format: API[:format] }
40
+
41
+ url = API[:endpoint] + "/api?" + URI.encode_www_form(param: param.to_json, public: public.to_json)
42
+
43
+ JSON.parse(eat url, :openssl_verify_mode => 'none')
44
+ end
45
+
46
+ def get_access_token_from_api
47
+ raise HOWTO_CONFIG unless @app_key or @app_secret
48
+
49
+ url = API[:endpoint] + "/token?" + URI.encode_www_form(grant_type: "client_credential",
50
+ appkey: @app_key,
51
+ secret: @app_secret)
52
+
53
+ result = JSON.parse(eat url, :openssl_verify_mode => 'none').fetch('result', {})
54
+
55
+ @expiry_time = Time.now + result['expire_in'] - 120
56
+ @access_token = result['access_token']
57
+
58
+ @access_token ? @access_token : raise("Get access_token Error:" + "url: #{url}" + result.to_s)
59
+ end
60
+
61
+ def access_token_expired?
62
+ return true unless @expiry_time
63
+ Time.now > @expiry_time
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'weidian_open/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "weidian_open"
8
+ spec.version = WeidianOpen::VERSION
9
+ spec.authors = ["YanyingWang"]
10
+ spec.email = ["yanyingwang1@gmail.com"]
11
+ spec.summary = %q{WeidianOpen}
12
+ spec.description = %q{Weidian Open Platform(微店开放平台) API in Ruby}
13
+ spec.homepage = "https://github.com/yanyingwang/weidian_open"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weidian_open
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - YanyingWang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Weidian Open Platform(微店开放平台) API in Ruby
42
+ email:
43
+ - yanyingwang1@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/weidian_open.rb
55
+ - lib/weidian_open/version.rb
56
+ - weidian_open.gemspec
57
+ homepage: https://github.com/yanyingwang/weidian_open
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: WeidianOpen
81
+ test_files: []
82
+ has_rdoc: