buscape 0.0.1
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +27 -0
- data/Rakefile +1 -0
- data/buscape.gemspec +22 -0
- data/buscape.rb +55 -0
- data/lib/buscape.rb +5 -0
- data/lib/buscape/base.rb +57 -0
- data/lib/buscape/version.rb +3 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
== BuscaPé
|
2
|
+
|
3
|
+
'Beware: This gem is under development and has not been tested on production environment yet.'
|
4
|
+
|
5
|
+
This is the lightweight wrapper for BuscaPé API. (http://developer.buscape.com)
|
6
|
+
|
7
|
+
= How to install?
|
8
|
+
|
9
|
+
Simple as:
|
10
|
+
|
11
|
+
gem install buscape
|
12
|
+
|
13
|
+
= How to use?
|
14
|
+
|
15
|
+
First a new 'Buscape::Base' object with two parameters (application_id, sandbox? (default: false)):
|
16
|
+
|
17
|
+
b = Buscape::Base.new("you_application_id")
|
18
|
+
|
19
|
+
Then you can use like this:
|
20
|
+
|
21
|
+
b.category(77).products
|
22
|
+
|
23
|
+
This get all products in the cellphone category.
|
24
|
+
|
25
|
+
Easy, huh? :P
|
26
|
+
|
27
|
+
Help me improving this gem (and the documentation of course)! Fork this project and feel free to help. :)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/buscape.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "buscape/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "buscape"
|
7
|
+
s.version = Buscape::VERSION
|
8
|
+
s.authors = ["Estevao Mascarenhas"]
|
9
|
+
s.email = ["estevao.am@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/estevaoam/buscape"
|
11
|
+
s.summary = %q{A lightweight wrapper for BuscaPe API.}
|
12
|
+
s.description = %q{A lightweight wrapper for BuscaPe API.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "buscape"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency("httparty", ">= 0.7.7")
|
22
|
+
end
|
data/buscape.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class BuscaPe
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
|
8
|
+
raise "You need to inform your :application_id" if options[:application_id].nil?
|
9
|
+
|
10
|
+
@base_uri = "sandbox.buscape.com/service" unless options[:sandbox].nil? || !options[:sandbox]
|
11
|
+
@application_id = options[:application_id];
|
12
|
+
|
13
|
+
@uris = {
|
14
|
+
:categories => "findCategoryList",
|
15
|
+
:products => "findProductList",
|
16
|
+
:ratings => "viewUserRatings",
|
17
|
+
:oferts => "findOfferList",
|
18
|
+
:details => "viewProductDetails"
|
19
|
+
}
|
20
|
+
|
21
|
+
@params = {
|
22
|
+
:category => "categoryId",
|
23
|
+
:product => "productId",
|
24
|
+
:top_products => "topProducts",
|
25
|
+
:seller => "sellerId"
|
26
|
+
}
|
27
|
+
|
28
|
+
@data = {}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.method_missing(method, *args, &block)
|
34
|
+
if @uris.map {|v, k| v }.include? method
|
35
|
+
self.fetch_api(method)
|
36
|
+
else
|
37
|
+
@data.merge!({method => args[0]})
|
38
|
+
self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.fetch_api(method)
|
43
|
+
raise "Method '#{method}' doesn't exist!" if @uris[method].blank?
|
44
|
+
|
45
|
+
@uris[method] = "viewSellerDetails" if method === :details && !@data[:seller].blank? && @data[:product].blank?
|
46
|
+
|
47
|
+
url = "http://#{@base_uri}/#{@uris[method]}/#{@application_id}/"
|
48
|
+
|
49
|
+
@data.each { |sym, value|
|
50
|
+
url += ((url[-1, 1] == "/") ? "?" : "&") + "#{(@params[sym].blank?) ? sym.to_s : @params[sym]}=#{value}"
|
51
|
+
}
|
52
|
+
|
53
|
+
self.get(url)
|
54
|
+
end
|
55
|
+
end
|
data/lib/buscape.rb
ADDED
data/lib/buscape/base.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Buscape
|
2
|
+
class Base
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def initialize(application_id, sandbox = false)
|
6
|
+
raise "You need to inform your :application_id" if application_id.nil?
|
7
|
+
|
8
|
+
@env = (sandbox) ? 'sandbox' : 'bws'
|
9
|
+
|
10
|
+
@application_id = application_id;
|
11
|
+
|
12
|
+
@uris = {
|
13
|
+
:categories => "findCategoryList",
|
14
|
+
:products => "findProductList",
|
15
|
+
:ratings => "viewUserRatings",
|
16
|
+
:oferts => "findOfferList",
|
17
|
+
:details => "viewProductDetails"
|
18
|
+
}
|
19
|
+
|
20
|
+
@params = {
|
21
|
+
:category => "categoryId",
|
22
|
+
:product => "productId",
|
23
|
+
:top_products => "topProducts",
|
24
|
+
:seller => "sellerId"
|
25
|
+
}
|
26
|
+
|
27
|
+
@data = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def method_missing(method, *args, &block)
|
33
|
+
if @uris.map {|v, k| v }.include? method
|
34
|
+
fetch_api(method)
|
35
|
+
else
|
36
|
+
@data.merge!({method => args[0]})
|
37
|
+
self
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch_api(method)
|
42
|
+
raise "Method '#{method}' doesn't exist!" if @uris[method].blank?
|
43
|
+
|
44
|
+
@uris[method] = "viewSellerDetails" if method === :details && !@data[:seller].blank? && @data[:product].blank?
|
45
|
+
|
46
|
+
url = "http://#{@env}.buscape.com/service/#{@uris[method]}/#{@application_id}/"
|
47
|
+
|
48
|
+
@data.each { |sym, value|
|
49
|
+
url += ((url[-1, 1] == "/") ? "?" : "&") + "#{(@params[sym].blank?) ? sym.to_s : @params[sym]}=#{value}"
|
50
|
+
}
|
51
|
+
|
52
|
+
res = self.class.get(url)
|
53
|
+
|
54
|
+
res.parsed_response["Result"] unless res.nil?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buscape
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Estevao Mascarenhas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-13 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.7.7
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: A lightweight wrapper for BuscaPe API.
|
27
|
+
email:
|
28
|
+
- estevao.am@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- README.markdown
|
39
|
+
- Rakefile
|
40
|
+
- buscape.gemspec
|
41
|
+
- buscape.rb
|
42
|
+
- lib/buscape.rb
|
43
|
+
- lib/buscape/base.rb
|
44
|
+
- lib/buscape/version.rb
|
45
|
+
homepage: http://github.com/estevaoam/buscape
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: buscape
|
68
|
+
rubygems_version: 1.8.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: A lightweight wrapper for BuscaPe API.
|
72
|
+
test_files: []
|
73
|
+
|