RTop 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -18,9 +18,48 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- rtop = RTop::RTop.new(File.join('config', 'taobao.yml'))
22
- item = rtop.get_item(1500022659003)
23
- puts item["title"]
21
+ ### Use in irb
22
+ 1. check rtop version in terminal:
23
+
24
+ > rtop -v
25
+
26
+ 2. generate rtop configuration file:
27
+
28
+ > rtop generate
29
+
30
+ 3. go into irb, and type:
31
+
32
+ ```ruby
33
+ > rtop = RTop::RTop.new() # by default will use taobao.yml in current folder or ./config folder
34
+ > item = rtop.get_item(1500022659003) # default to sandbox mode, so this item is from http://mini.tbsandbox.com/buyer/items_result.htm
35
+ > puts item["title"]
36
+ ```
37
+
38
+ ### Use with rails app
39
+ Simply put configuration file to yourApp/config/ folder, and start to use:
40
+
41
+ rtop = RTop::RTop.new()
42
+ rtop...
43
+
44
+ ### Sample of the configuration file
45
+
46
+ defaults: &DEFAULTS
47
+ app_key: test
48
+ secret_key: test
49
+
50
+ development:
51
+ <<: *DEFAULTS
52
+ env: development # will use sandbox api url
53
+
54
+ test:
55
+ <<: *DEFAULTS
56
+ env: test # will use sandbox api url
57
+
58
+ production:
59
+ <<: *DEFAULTS
60
+ env: production # will use production api url
61
+ app_key: 1122334455
62
+ secret_key: 23424242424234234242423423
24
63
 
25
64
  ## Contributing
26
65
 
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Rtop
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Thorfile CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'thor'
2
- require './lib/rtop/generators/config'
2
+ require 'rtop/generators/config'
3
3
 
4
4
  module RTop
5
5
  class Cli < Thor
6
6
  desc "rspec", "Run RSpec Testing"
7
7
  def rspec
8
- exec "rspec --color --format=documentation spec"
8
+ exec "rspec ./config --color --format=documentation spec"
9
9
  end
10
10
  end
11
11
  end
data/bin/rtop ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require 'rtop/runner'
5
+
6
+ RTop::Runner.start
@@ -1,12 +1,29 @@
1
1
  require 'thor/group'
2
+ require 'fileutils'
2
3
 
3
4
  module RTop
4
5
  module Generators
5
6
  class Config < Thor::Group
6
7
  include Thor::Actions
7
8
 
9
+ argument :path, :type => :string, :optional => true
10
+
8
11
  def copy_config
9
- template "taobao.yml", File.join('config', 'taobao.yml')
12
+ file_path = path
13
+ unless file_path
14
+ file_path = File.join(Dir.pwd, 'config')
15
+ if File.directory?(file_path)
16
+ say("Seems like there is a /config folder, do you want rtop to generate configuration file to this folder?")
17
+ y = ask("Yes to generate to /config folder, others to generate to current folder. (Y|N): ")
18
+ unless "Y".casecmp(y) == 0
19
+ file_path = Dir.pwd
20
+ end
21
+ else
22
+ file_path = Dir.pwd
23
+ end
24
+ end
25
+
26
+ template "taobao.yml", File.join(file_path, 'taobao.yml')
10
27
  end
11
28
 
12
29
  def self.source_root
data/lib/RTop/rtop.rb CHANGED
@@ -4,6 +4,7 @@ require "base64"
4
4
  require "uri"
5
5
  require 'httparty'
6
6
  require "yaml"
7
+ require 'fileutils'
7
8
 
8
9
  module RTop
9
10
  class RTop
@@ -15,7 +16,18 @@ module RTop
15
16
  API_OPTION = { "format" => "json", "v" => "2.0", "sign_method" => "md5" }
16
17
 
17
18
  def initialize(config_file = nil)
18
- config_file ||= "#{Rails.root}/config/taobao.yml"
19
+ unless config_file
20
+ if defined? Rails
21
+ config_file = "#{Rails.root}/config/taobao.yml"
22
+ else
23
+ config_file = File.join(Dir.pwd, 'config/taobao.yml')
24
+ unless File.file?(config_file)
25
+ config_file = File.join(Dir.pwd, 'taobao.yml')
26
+ end
27
+ end
28
+ raise "taobao.yml not found, generate one with 'rtop generate [path]'." unless File.file?(config_file)
29
+ end
30
+
19
31
  @settings = YAML.load_file(config_file)
20
32
  @settings = (defined? Rails) ? @settings[Rails.env] : @settings["defaults"]
21
33
  end
@@ -0,0 +1,19 @@
1
+ require 'thor'
2
+ require 'rtop/version'
3
+ require 'rtop/generators/config.rb'
4
+
5
+ class RTop::Runner < Thor
6
+ map "-v" => :version
7
+
8
+ desc "version", "Show RTop version"
9
+ def version
10
+ say "RTop #{RTop::VERSION}"
11
+ end
12
+
13
+ desc "generate", "Generate configuration file for rtop"
14
+ method_options :path => :string, :optional => true
15
+ def generate
16
+ RTop::Generators::Config.start([options[:path]])
17
+ end
18
+
19
+ end
data/lib/RTop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RTop
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/rtop_spec.rb CHANGED
@@ -1,17 +1,21 @@
1
1
  require 'rtop'
2
2
  require 'rtop/generators/config'
3
+ require 'rtop/runner'
3
4
 
4
5
  describe RTop::RTop do
5
6
 
7
+ it "version test" do
8
+ RTop::Runner.start(["-v"])
9
+ end
10
+
11
+ it "generate test" do
12
+ RTop::Runner.start(["generate"])
13
+ end
14
+
6
15
  it "get taobao item information" do
7
16
  item = RTop::RTop.new(File.join('config', 'taobao.yml')).get_item(1500022659003)
8
17
  item.should_not equal(nil)
9
18
  item["title"].should_not equal(nil)
10
19
  end
11
-
12
-
13
- it "generate the taobao configuration file taobao.yml" do
14
- RTop::Generators::Config.start()
15
- end
16
20
 
17
21
  end
data/taobao.yml ADDED
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RTop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-14 00:00:00.000000000 Z
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -62,7 +62,8 @@ dependencies:
62
62
  description: ! 'Library for Taobao Open API '
63
63
  email:
64
64
  - mingliangfeng@gmail.com
65
- executables: []
65
+ executables:
66
+ - rtop
66
67
  extensions: []
67
68
  extra_rdoc_files: []
68
69
  files:
@@ -71,16 +72,20 @@ files:
71
72
  - Gemfile
72
73
  - LICENSE
73
74
  - README.md
75
+ - README.rdoc
74
76
  - RTop.gemspec
75
77
  - Rakefile
76
78
  - Thorfile
79
+ - bin/rtop
77
80
  - config/taobao.yml
78
81
  - lib/RTop/generators/config.rb
79
82
  - lib/RTop/generators/taobao.yml
80
83
  - lib/RTop/rtop.rb
84
+ - lib/RTop/runner.rb
81
85
  - lib/RTop/version.rb
82
86
  - lib/rtop.rb
83
87
  - spec/rtop_spec.rb
88
+ - taobao.yml
84
89
  homepage: ''
85
90
  licenses: []
86
91
  post_install_message: