RTop 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
+ .DS_Store
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>rtop</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>com.aptana.ruby.core.rubynature</nature>
16
+ </natures>
17
+ </projectDescription>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in RTop.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrew Feng
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.
@@ -0,0 +1,31 @@
1
+ # RTop
2
+
3
+ Quick start to use Taobao Open API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'RTop'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install RTop
18
+
19
+ ## Usage
20
+
21
+ rtop = RTop::RTop.new(File.join('config', 'taobao.yml'))
22
+ item = rtop.get_item(1500022659003)
23
+ puts item["title"]
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/RTop/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Andrew Feng"]
6
+ gem.email = ["mingliangfeng@gmail.com"]
7
+ gem.description = %q{Library for Taobao Open API }
8
+ gem.summary = %q{Quick start to use Taobao Open API.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "RTop"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = RTop::VERSION
17
+
18
+ gem.add_development_dependency "rspec", "~> 2.6"
19
+ gem.add_development_dependency "thor"
20
+
21
+ gem.add_dependency "httparty"
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ require 'thor'
2
+ require './lib/rtop/generators/config'
3
+
4
+ module RTop
5
+ class Cli < Thor
6
+ desc "rspec", "Run RSpec Testing"
7
+ def rspec
8
+ exec "rspec --color --format=documentation spec"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ defaults: &DEFAULTS
2
+ app_key: test
3
+ secret_key: test
4
+
5
+ development:
6
+ <<: *DEFAULTS
7
+ env: development # will use sandbox api url
8
+
9
+ test:
10
+ <<: *DEFAULTS
11
+ env: test # will use sandbox api url
12
+
13
+ production:
14
+ <<: *DEFAULTS
15
+ env: production # will use production api url
16
+ app_key: 1122334455
17
+ secret_key: 23424242424234234242423423
@@ -0,0 +1,17 @@
1
+ require 'thor/group'
2
+
3
+ module RTop
4
+ module Generators
5
+ class Config < Thor::Group
6
+ include Thor::Actions
7
+
8
+ def copy_config
9
+ template "taobao.yml", File.join('config', 'taobao.yml')
10
+ end
11
+
12
+ def self.source_root
13
+ File.dirname(__FILE__)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ defaults: &DEFAULTS
2
+ app_key: test
3
+ secret_key: test
4
+
5
+ development:
6
+ <<: *DEFAULTS
7
+ env: development # will use sandbox api url
8
+
9
+ test:
10
+ <<: *DEFAULTS
11
+ env: test # will use sandbox api url
12
+
13
+ production:
14
+ <<: *DEFAULTS
15
+ env: production # will use production api url
16
+ app_key: 1122334455
17
+ secret_key: 23424242424234234242423423
@@ -0,0 +1,72 @@
1
+ require "date"
2
+ require "digest"
3
+ require "base64"
4
+ require "uri"
5
+ require 'httparty'
6
+ require "yaml"
7
+
8
+ module RTop
9
+ class RTop
10
+ include HTTParty
11
+
12
+ API_URL = 'http://gw.api.taobao.com/router/rest'
13
+ API_URL_SANDBOX = 'http://gw.api.tbsandbox.com/router/rest'
14
+
15
+ API_OPTION = { "format" => "json", "v" => "2.0", "sign_method" => "md5" }
16
+
17
+ def initialize(config_file = nil)
18
+ config_file ||= "#{Rails.root}/config/taobao.yml"
19
+ @settings = YAML.load_file(config_file)
20
+ @settings = (defined? Rails) ? @settings[Rails.env] : @settings["defaults"]
21
+ end
22
+
23
+ def get_item(item_id)
24
+ response = self.get("taobao.item.get", { "num_iid" => item_id,
25
+ "fields" => "title,price,ems_fee,express_fee,detail_url,item_imgs,pic_url,location" })
26
+
27
+ if response and response.parsed_response and response.parsed_response["item_get_response"] and response.parsed_response["item_get_response"]["item"]
28
+ return response.parsed_response["item_get_response"]["item"]
29
+ end
30
+ end
31
+
32
+ def get(method, options)
33
+ options = prepare_options(method, options)
34
+ self.class.get(api_url, :query => options)
35
+ end
36
+
37
+ def post(url, options)
38
+ options = prepare_options(method, options)
39
+ self.class.post(api_url, :query => options)
40
+ end
41
+
42
+ def put(url, options)
43
+ options = prepare_options(method, options)
44
+ self.class.put(api_url, :query => options)
45
+ end
46
+
47
+ def delete(url, options)
48
+ options = prepare_options(method, options)
49
+ self.class.delete(api_url, :query => options)
50
+ end
51
+
52
+ protected
53
+ def api_url
54
+ @settings["env"] == "production" ? API_URL : API_URL_SANDBOX
55
+ end
56
+
57
+ def md5_signature(params, secret)
58
+ params_sorted = params.sort_by { |k,v| k.to_s }
59
+ params_str = params_sorted.flatten.join
60
+ params_token = "#{secret}#{params_str}#{secret}"
61
+ Digest::MD5.hexdigest(params_token).upcase
62
+ end
63
+
64
+ def prepare_options(method, options)
65
+ opts = { "method" => method,
66
+ "timestamp" => Time.now.strftime("%Y-%m-%d %H:%M:%S"),
67
+ "app_key" => @settings["app_key"] }.merge(API_OPTION)
68
+ opts = opts.merge(options || {})
69
+ opts.merge({"sign" => md5_signature(opts, @settings["secret_key"])})
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ module RTop
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'rtop/rtop'
2
+ require 'rtop/generators/config'
3
+
4
+ module RTop
5
+ end
@@ -0,0 +1,17 @@
1
+ require 'rtop'
2
+ require 'rtop/generators/config'
3
+
4
+ describe RTop::RTop do
5
+
6
+ it "get taobao item information" do
7
+ item = RTop::RTop.new(File.join('config', 'taobao.yml')).get_item(1500022659003)
8
+ item.should_not equal(nil)
9
+ item["title"].should_not equal(nil)
10
+ end
11
+
12
+
13
+ it "generate the taobao configuration file taobao.yml" do
14
+ RTop::Generators::Config.start()
15
+ end
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: RTop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Feng
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: thor
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: httparty
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
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: ! 'Library for Taobao Open API '
63
+ email:
64
+ - mingliangfeng@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .project
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - RTop.gemspec
75
+ - Rakefile
76
+ - Thorfile
77
+ - config/taobao.yml
78
+ - lib/RTop/generators/config.rb
79
+ - lib/RTop/generators/taobao.yml
80
+ - lib/RTop/rtop.rb
81
+ - lib/RTop/version.rb
82
+ - lib/rtop.rb
83
+ - spec/rtop_spec.rb
84
+ homepage: ''
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.21
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Quick start to use Taobao Open API.
108
+ test_files:
109
+ - spec/rtop_spec.rb