buscape_api 0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'httparty'
4
+
5
+ group :test do
6
+ gem 'webmock'
7
+ gem 'vcr'
8
+ gem 'turn'
9
+ gem 'rake'
10
+ gem 'require_all'
11
+ gem 'minitest'
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.8)
5
+ ansi (1.4.3)
6
+ crack (0.3.1)
7
+ httparty (0.8.3)
8
+ multi_json (~> 1.0)
9
+ multi_xml
10
+ minitest (3.2.0)
11
+ multi_json (1.3.6)
12
+ multi_xml (0.5.1)
13
+ rake (0.9.2.2)
14
+ require_all (1.2.1)
15
+ turn (0.9.6)
16
+ ansi
17
+ vcr (2.2.2)
18
+ webmock (1.8.7)
19
+ addressable (>= 2.2.7)
20
+ crack (>= 0.1.7)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ httparty
27
+ minitest
28
+ rake
29
+ require_all
30
+ turn
31
+ vcr
32
+ webmock
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.test_files = FileList.new('spec/lib/buscape_api/*_spec.rb')
5
+ t.verbose = true
6
+ end
7
+
8
+ task :default => :test
data/Readme.rdoc ADDED
@@ -0,0 +1,51 @@
1
+ = Buscape API
2
+
3
+ == Instalation
4
+
5
+ gem install buscape_api
6
+
7
+ == Usage
8
+
9
+ First require the gem:
10
+
11
+ require 'buscape_api'
12
+
13
+ Then instantiate the Buscape class
14
+
15
+ buscape = Buscape.new(:app_id => 'your_app_key')
16
+
17
+ The Buscape class takes also two optional parameters which are *:sandbox*(should be true) and *:country_code*(check about it's usage at http://developer.buscape.com/api/)
18
+
19
+ An example using all the parameters is:
20
+
21
+ buscape = Buscape.new(:app_id => 'your_app_key', :country_code => 'BR', :sandbox => true)
22
+
23
+ Now you have the following methods to be used with your object:
24
+
25
+ * categories
26
+ * products
27
+ * offers
28
+ * top_products
29
+ * user_ratings
30
+ * product_details
31
+ * seller_details
32
+
33
+ After that, use the where method passing the parameters(follow http://developer.buscape.com/api/ parameters usage).
34
+
35
+ ===Example:
36
+
37
+ require 'buscape_api'
38
+
39
+ buscape = Buscape.new(:app_id => '12345', :sandbox => true)
40
+
41
+ buscape.products.where(:categoryId => 77) # Returns all products of category 77 in array/hash style.
42
+
43
+ buscape.top_products.where(:keyword => 'Celular') # Returns all top products that is a Celular
44
+
45
+ == Contributing
46
+
47
+ Feel free to submit any ideas, issues or pull requests. If you have the time, write some tests/docs(should be simple) for it.
48
+
49
+ === Contributors
50
+
51
+ None yet.
@@ -0,0 +1,20 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "buscape_api"
5
+ s.version = "0.5"
6
+ s.email = ["t@art-is-t.me"]
7
+ s.authors = ["Thiago Fernandes Massa"]
8
+ s.homepage = "http://github.com/thiagofm/buscape_api"
9
+ s.summary = %q{Buscape API wrapper}
10
+ s.description = %q{A Buscape API wrapper}
11
+
12
+ s.rubyforge_project = "buscape_api"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency("httparty", ">= 0.8.3")
20
+ end
@@ -0,0 +1,14 @@
1
+ require "require_all"
2
+
3
+ # Loading and requiring all api files
4
+ require_all 'lib/buscape_api'
5
+
6
+ class Buscape
7
+ def initialize(options = {})
8
+ @options = options
9
+ end
10
+
11
+ def method_missing(method, *args)
12
+ Base.new(@options).send(method, args.first)
13
+ end
14
+ end
@@ -0,0 +1,63 @@
1
+ require 'httparty'
2
+
3
+ class Base
4
+ include HTTParty
5
+
6
+ def initialize(options = {})
7
+ raise "No :app_id set" unless options.include? :app_id
8
+ options[:format] = 'json' # JSON is more lightweight than xml
9
+ @options = options
10
+ @services = [
11
+ { :method => :categories, :service => :findCategoryList },
12
+ { :method => :products, :service => :findProductList },
13
+ { :method => :offers, :service => :findOffersList, :item => :offer },
14
+ { :method => :top_products, :service => :topProducts },
15
+ { :method => :user_ratings, :service => :viewUserRatings },
16
+ { :method => :product_details, :service => :viewProductDetailst },
17
+ { :method => :seller_details, :service => :viewSellerDetails }
18
+ ]
19
+ @methods = @services.map { |service| service[:method] }
20
+ @url = base_url
21
+ end
22
+
23
+ def base_url
24
+ @options[:sandbox] ? "http://sandbox.buscape.com" : "http://bws.buscape.com"
25
+ end
26
+
27
+ def select_service(method)
28
+ @services.each do |s|
29
+ @service = s[:service] if s.values.include? method
30
+ end
31
+ @url << '/service/' << @service.to_s
32
+ end
33
+
34
+ def set_app_id
35
+ @url << '/' << @options[:app_id]
36
+ end
37
+
38
+ def select_country
39
+ @url << '/' << @options[:country_code]
40
+ end
41
+
42
+ def parameterize(options)
43
+ parameters = String.new
44
+
45
+ options.keys.each_with_index do |parameter,index|
46
+ index == 0 ? @url << "/?#{parameter}=#{options[parameter]}" : @url << "&#{parameter}=#{options[parameter]}"
47
+ end
48
+ end
49
+
50
+ def method_missing(method, *args)
51
+ if @methods.include? method
52
+ select_service method
53
+ set_app_id
54
+ select_country if @options.include? :country_code
55
+ self
56
+ elsif method == :where
57
+ parameterize args.first
58
+ response = self.class.get(@url)['Result']
59
+ else
60
+ raise NoMethodError
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,9 @@
1
+ require (File.expand_path('./../../../spec_helper', __FILE__))
2
+
3
+ describe Buscape::Base do
4
+
5
+ it "must work" do
6
+ "Yay!".must_be_instance_of String
7
+ end
8
+
9
+ end
@@ -0,0 +1,21 @@
1
+ # require dependancies
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'vcr'
5
+ require 'turn'
6
+ require 'ap'
7
+ require 'require_all'
8
+
9
+ # require lib
10
+ require_all 'lib/'
11
+
12
+ Turn.config do |c|
13
+ c.format = :outline
14
+ c.trace = true
15
+ c.natural = true
16
+ end
17
+
18
+ VCR.config do |c|
19
+ c.cassette_library_dir = 'spec/fixtures/buscape_api'
20
+ c.hook_into :webmock
21
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buscape_api
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.5'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thiago Fernandes Massa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &2157367040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2157367040
25
+ description: A Buscape API wrapper
26
+ email:
27
+ - t@art-is-t.me
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .DS_Store
33
+ - Gemfile
34
+ - Gemfile.lock
35
+ - Rakefile
36
+ - Readme.rdoc
37
+ - buscape_api.gemspec
38
+ - lib/buscape_api.rb
39
+ - lib/buscape_api/base.rb
40
+ - spec/lib/buscape_api/base_spec.rb
41
+ - spec/spec_helper.rb
42
+ homepage: http://github.com/thiagofm/buscape_api
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project: buscape_api
62
+ rubygems_version: 1.8.15
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Buscape API wrapper
66
+ test_files:
67
+ - spec/lib/buscape_api/base_spec.rb
68
+ - spec/spec_helper.rb