fletcher 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  gem "hashie"
4
4
  gem "nokogiri"
5
5
  gem "money"
6
- gem "commander"
6
+ gem "thor"
7
7
 
8
8
  group :development do
9
9
  gem "shoulda", ">= 0"
data/Gemfile.lock CHANGED
@@ -4,15 +4,12 @@ GEM
4
4
  activesupport (3.2.2)
5
5
  i18n (~> 0.6)
6
6
  multi_json (~> 1.0)
7
- commander (4.1.2)
8
- highline (~> 1.6.11)
9
7
  diff-lcs (1.1.3)
10
8
  factory_girl (2.6.4)
11
9
  activesupport (>= 2.3.9)
12
10
  fakeweb (1.3.0)
13
11
  git (1.2.5)
14
12
  hashie (1.2.0)
15
- highline (1.6.15)
16
13
  i18n (0.6.0)
17
14
  jeweler (1.6.4)
18
15
  bundler (~> 1.0)
@@ -35,6 +32,7 @@ GEM
35
32
  diff-lcs (~> 1.1.2)
36
33
  rspec-mocks (2.7.0)
37
34
  shoulda (2.11.3)
35
+ thor (0.16.0)
38
36
  vcr (2.2.5)
39
37
 
40
38
  PLATFORMS
@@ -42,7 +40,6 @@ PLATFORMS
42
40
 
43
41
  DEPENDENCIES
44
42
  bundler
45
- commander
46
43
  factory_girl
47
44
  fakeweb
48
45
  hashie
@@ -53,4 +50,5 @@ DEPENDENCIES
53
50
  rcov
54
51
  rspec
55
52
  shoulda
53
+ thor
56
54
  vcr
data/README.md CHANGED
@@ -89,8 +89,6 @@ ThinkGeek
89
89
 
90
90
 
91
91
 
92
-
93
-
94
92
  ## Attributes
95
93
 
96
94
  The following attributes/method are available for a product:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
data/bin/fletcher CHANGED
@@ -1,69 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
- require 'rubygems'
4
- require 'commander/import'
5
- require 'yaml'
6
- require File.expand_path("../../lib/fletcher", __FILE__)
7
- #require 'commander-foo'
8
-
9
- program :version, Fletcher.version #Commander-foo::VERSION
10
- program :description, 'A cross-website product information fetcher'
11
- program :help, 'Author', 'Dave Hulihan <dhulihan@gmail.com>'
12
- #default_command :fetch
13
-
14
- command :fetch do |c|
15
- c.syntax = 'fletcher fetch [URL]'
16
- c.summary = 'Fetch product information'
17
- c.description = ''
18
- c.example 'Fetch an amazon product', 'fletcher "http://www.example.com/product-id"'
19
- #c.option '--format [yaml|json]', String, 'The format of the product details'
20
- #c.option '--timeout SECONDS', Integer, 'Timeout in seconds'
21
- c.option '--only [name|description|price|image]', String, 'Fetch a single attribute from the product.'
22
- c.action do |args, options|
23
- # Do something or c.when_called Commander-foo::Commands::Hello
24
- options.default :format => :yaml
4
+ require "yaml"
5
+ require "thor"
25
6
 
26
- url = args.first
27
- if url
28
- product = Fletcher.fetch url
29
-
30
- # Prep output
31
- output_hash = Hash.new
32
- output_hash["name"] = product.name
33
- output_hash["description"] = product.description if product.description
34
- output_hash["price"] = product.price.format if product.price
35
- if product.image
36
- output_hash["image"] = {
37
- "src" => product.image.src
38
- }
39
- end
40
- output_hash["url"] = product.url
7
+ # Load the Fletcher core library
8
+ require File.expand_path("../../lib/fletcher", __FILE__)
41
9
 
42
- # Get single attribute
43
- if options.only
44
- case options.only
45
- when "image"
46
- value = output_hash["image"]["src"]
47
- else
48
- value = output_hash[options.only]
49
- end
50
- value ? say(value.to_s) : say("Unknown attribute: #{options.only}")
51
- else
52
- say output_hash.to_yaml
53
- end
54
- else
55
- puts c.syntax
56
- end
57
- end
58
- end
10
+ # Load the Fletcher command line interface utility
11
+ require File.expand_path("../../lib/fletcher/cli/utility", __FILE__)
59
12
 
60
- command :websites do |c|
61
- c.syntax = 'fletcher websites'
62
- c.summary = 'Get a list of supported websites'
63
- c.action do |args, options|
64
- say "Supported Websites:"
65
- for model in Fletcher.models.sort
66
- say "\t#{model.to_s.capitalize}"
67
- end
68
- end
69
- end
13
+ # Initialize the Fletcher command line utility
14
+ Fletcher::CLI::Utility.start
data/fletcher.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fletcher"
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dave Hulihan", "Hulihan Applications"]
12
- s.date = "2012-10-26"
12
+ s.date = "2012-11-06"
13
13
  s.description = "Easily fetch product/model information from third party websites such as Amazon, eBay, etc."
14
14
  s.email = "dave@hulihanapplications.com"
15
15
  s.executables = ["fletcher"]
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "config/locales/fletcher.en.yml",
31
31
  "fletcher.gemspec",
32
32
  "lib/fletcher.rb",
33
+ "lib/fletcher/cli/utility.rb",
33
34
  "lib/fletcher/data.rb",
34
35
  "lib/fletcher/models/amazon.rb",
35
36
  "lib/fletcher/models/base.rb",
@@ -77,7 +78,7 @@ Gem::Specification.new do |s|
77
78
  s.add_runtime_dependency(%q<hashie>, [">= 0"])
78
79
  s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
79
80
  s.add_runtime_dependency(%q<money>, [">= 0"])
80
- s.add_runtime_dependency(%q<commander>, [">= 0"])
81
+ s.add_runtime_dependency(%q<thor>, [">= 0"])
81
82
  s.add_development_dependency(%q<shoulda>, [">= 0"])
82
83
  s.add_development_dependency(%q<bundler>, [">= 0"])
83
84
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -91,7 +92,7 @@ Gem::Specification.new do |s|
91
92
  s.add_dependency(%q<hashie>, [">= 0"])
92
93
  s.add_dependency(%q<nokogiri>, [">= 0"])
93
94
  s.add_dependency(%q<money>, [">= 0"])
94
- s.add_dependency(%q<commander>, [">= 0"])
95
+ s.add_dependency(%q<thor>, [">= 0"])
95
96
  s.add_dependency(%q<shoulda>, [">= 0"])
96
97
  s.add_dependency(%q<bundler>, [">= 0"])
97
98
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -106,7 +107,7 @@ Gem::Specification.new do |s|
106
107
  s.add_dependency(%q<hashie>, [">= 0"])
107
108
  s.add_dependency(%q<nokogiri>, [">= 0"])
108
109
  s.add_dependency(%q<money>, [">= 0"])
109
- s.add_dependency(%q<commander>, [">= 0"])
110
+ s.add_dependency(%q<thor>, [">= 0"])
110
111
  s.add_dependency(%q<shoulda>, [">= 0"])
111
112
  s.add_dependency(%q<bundler>, [">= 0"])
112
113
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
data/lib/fletcher.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  # = Fletcher
2
2
  # Author:: Dave Hulihan - 2012
3
3
  require "uri"
4
- require "fletcher/data"
5
- require "fletcher/string"
6
- require "fletcher/nokogiri"
4
+
5
+ require File.expand_path("fletcher/data", File.dirname(__FILE__))
6
+ require File.expand_path("fletcher/string", File.dirname(__FILE__))
7
+ require File.expand_path("fletcher/nokogiri", File.dirname(__FILE__))
7
8
 
8
9
  module Fletcher
10
+ # Module Methods
9
11
  class << self
10
12
  # Detect model by url
11
13
  # Fletcher.identify_model("http://www.amazon.com/whatever") # => :amazon
@@ -60,25 +62,30 @@ module Fletcher
60
62
  File.expand_path("../..", __FILE__)
61
63
  end
62
64
 
63
- # Create mattrs
64
- attr_accessor :models
65
+ def models
66
+ models = Array.new
67
+ Dir[File.join(File.dirname(__FILE__), "fletcher", "models", "*.rb")].each do |f|
68
+ model = File.basename(f, ".rb").to_sym
69
+ models << model unless model == :base
70
+ end
71
+ return models
72
+ end
73
+ end
74
+
75
+ LIBRARY_PATH = File.join(File.dirname(__FILE__), 'fletcher')
76
+ CLI_PATH = File.join(LIBRARY_PATH, 'cli')
77
+ MODEL_PATH = File.join(LIBRARY_PATH, 'models')
78
+
79
+ # Autoload CLI
80
+ module CLI
81
+ autoload :Utility, File.join(CLI_PATH, 'utility')
65
82
  end
66
-
67
- # Initialize models mattr & Load models array from dir
68
- @models = Array.new
69
- Dir[File.join(File.dirname(__FILE__), "fletcher", "models", "*.rb")].each do |f|
70
- model = File.basename(f, ".rb").to_sym
71
- @models << model unless model == :base
72
- end
73
83
 
74
- # Load Models/Models
84
+ # Autoload Models
75
85
  module Model
76
- # Dir[File.join(dir, "*.rb")].each do |f|
77
- # autoload f
78
- # end
79
- autoload :Base, 'fletcher/models/base'
86
+ autoload :Base, File.join(MODEL_PATH, "base")
80
87
  for model in Fletcher.models
81
- autoload model.to_s.capitalize.to_sym, "fletcher/models/#{model}"
88
+ autoload model.to_s.capitalize.to_sym, File.join(MODEL_PATH, model.to_s)
82
89
  end
83
- end
90
+ end
84
91
  end
@@ -0,0 +1,55 @@
1
+
2
+ module Fletcher
3
+ module CLI
4
+ class Utility < Thor
5
+ include Thor::Actions
6
+
7
+ method_option :format, :type => :string, :default => :yaml, :aliases => "-f"
8
+ method_option :only, :type => :string, :aliases => "-o", :desc => "Fetch a single attribute [name|description|image|price]", :banner => "ATTRIBUTE"
9
+
10
+ desc 'fetch [URL]', "Fetch Product information\n\n" +
11
+ "Example:\n\s\sfletcher fetch 'http://www.amazon.com/gp/product/B004HZYA6E/'"
12
+ def fetch(url)
13
+ product = Fletcher.fetch url
14
+
15
+ # Prep output
16
+ output_hash = Hash.new
17
+ output_hash["name"] = product.name
18
+ output_hash["description"] = product.description if product.description
19
+ output_hash["price"] = product.price.format if product.price
20
+ if product.image
21
+ output_hash["image"] = Hash.new
22
+ output_hash["image"]["src"] = product.image.src
23
+ end
24
+ output_hash["url"] = product.url
25
+
26
+ # Get single attribute
27
+ if options[:only]
28
+ case options[:only]
29
+ when "image"
30
+ value = output_hash["image"]["src"]
31
+ else
32
+ value = output_hash[options[:only]]
33
+ end
34
+ value ? say(value.to_s) : say("Unknown attribute: #{options[:only]}")
35
+ else
36
+ say output_hash.to_yaml
37
+ end
38
+ end
39
+
40
+ desc "websites", "Get a list of supported websites"
41
+ def websites
42
+ say "Supported Websites:"
43
+ for model in Fletcher.models.sort
44
+ say "\t#{model.to_s.capitalize}"
45
+ end
46
+ end
47
+
48
+ map '-v' => :version
49
+ desc "version", "Get VERSION"
50
+ def version
51
+ say Fletcher.version
52
+ end
53
+ end
54
+ end
55
+ end
@@ -21,7 +21,10 @@ module Fletcher
21
21
  parse_price( doc.css('div.leftcol.game_description_column div.game_purchase_price.price').first_string )
22
22
 
23
23
  # Get Images
24
- self.images = doc.css('div.screenshot_holder a[@href]').attribute_array.collect{|img| img[:href] }
24
+ self.images = doc.css('div.screenshot_holder > a').collect do |node|
25
+ {:src => node.attribute("href").value}
26
+ end
27
+
25
28
  self.image = images.first
26
29
  end
27
30
  end
@@ -2,7 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Fletcher, :vcr do
4
4
  describe :fetch, :vcr do
5
-
5
+ it "should return correct model info" do
6
+ product = Fletcher.fetch Factory(:steam).url
7
+ puts product.image.inspect
8
+ end
6
9
  end
7
10
  end
8
11
 
@@ -18,8 +21,9 @@ describe Fletcher::Model::Steam, :vcr do
18
21
  model.description.should_not be_nil
19
22
  model.description.class.should == String
20
23
  model.price.should_not be_nil
21
- model.image.should_not be_nil
22
24
  model.images.should_not be_empty
25
+ model.image.should_not be_nil
26
+ model.image.src.should_not be_nil
23
27
  end
24
28
  end
25
29
  end
@@ -1,6 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Fletcher, :vcr do
4
+ describe :models do
5
+ it "should return an array of symbols" do
6
+ models = described_class.models
7
+ models.is_a?(Array).should == true
8
+ end
9
+ end
10
+
4
11
  context :models do
5
12
  describe :identify_model, :vcr do
6
13
  it "should raise an error when using an unsupported domain" do
@@ -31,13 +38,4 @@ describe Fletcher, :vcr do
31
38
  described_class.version.should_not be_nil
32
39
  end
33
40
  end
34
-
35
- describe :models do
36
- it "should return an array of models" do
37
- described_class.models.should_not be_nil
38
- # Test append
39
- described_class.models << :somemodel
40
- described_class.models.include?(:somemodel).should == true
41
- end
42
- end
43
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fletcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-26 00:00:00.000000000 Z
13
+ date: 2012-11-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hashie
@@ -61,7 +61,7 @@ dependencies:
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  - !ruby/object:Gem::Dependency
64
- name: commander
64
+ name: thor
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
@@ -242,6 +242,7 @@ files:
242
242
  - config/locales/fletcher.en.yml
243
243
  - fletcher.gemspec
244
244
  - lib/fletcher.rb
245
+ - lib/fletcher/cli/utility.rb
245
246
  - lib/fletcher/data.rb
246
247
  - lib/fletcher/models/amazon.rb
247
248
  - lib/fletcher/models/base.rb
@@ -290,7 +291,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
290
291
  version: '0'
291
292
  segments:
292
293
  - 0
293
- hash: 900298913943302851
294
+ hash: 1525293915751678679
294
295
  required_rubygems_version: !ruby/object:Gem::Requirement
295
296
  none: false
296
297
  requirements: