wine_dot_com_api_request 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +22 -0
- data/Manifest +9 -0
- data/README.rdoc +75 -0
- data/Rakefile +15 -0
- data/init.rb +1 -0
- data/lib/wine_dot_com_api_request.rb +134 -0
- data/lib/wine_dot_com_api_request/configuration.rb +4 -0
- data/test/wine_dot_com_api_request_test.rb +2 -0
- data/wine_dot_com_api_request.gemspec +31 -0
- metadata +70 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010 Christopher Meiklejohn
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
= Introduction
|
2
|
+
|
3
|
+
WineDotComApiRequest provides a simple no-frills interface to the Wine.com query API.
|
4
|
+
|
5
|
+
Its purpose is to eliminate the code duplication in setting up the request each time
|
6
|
+
you which to receive information from the API.
|
7
|
+
|
8
|
+
It returns pure JSON or XML depending on which type of response you request.
|
9
|
+
|
10
|
+
= Installation
|
11
|
+
|
12
|
+
To install, run:
|
13
|
+
|
14
|
+
$ sudo gem install wine_dot_com_api_request
|
15
|
+
|
16
|
+
Then, place your API key from wine.com in the lib/wine_dot_com_api_request/configuration.rb file.
|
17
|
+
|
18
|
+
= Examples
|
19
|
+
|
20
|
+
To perform a request, follow the example below:
|
21
|
+
|
22
|
+
w = WineDotComApiRequest.new(:search => 'mondavi cabernet',
|
23
|
+
:format => :xml,
|
24
|
+
:resource => :catalog,
|
25
|
+
:size => 1,
|
26
|
+
:offset => 0)
|
27
|
+
|
28
|
+
res = w.query
|
29
|
+
|
30
|
+
View the documentation for possible search arguments.
|
31
|
+
|
32
|
+
The query routine will return either the raw XML or JSON request, depending on which you specify.
|
33
|
+
|
34
|
+
= Documentation
|
35
|
+
|
36
|
+
You can generate documentation if you have the source by typing:
|
37
|
+
|
38
|
+
$ rake doc
|
39
|
+
|
40
|
+
= Release Notes
|
41
|
+
|
42
|
+
First release.
|
43
|
+
|
44
|
+
= Credits
|
45
|
+
|
46
|
+
WineDotComApiRequest is maintained by {Christopher Meiklejohn}[mailto:cmeik@me.com]. Contact me if you'd like to request any features or have any questions or feedback.
|
47
|
+
|
48
|
+
= License
|
49
|
+
|
50
|
+
WineDotComApiRequest is Copyright 2010 Christopher Meiklejohn.
|
51
|
+
|
52
|
+
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file, which is attached below:
|
53
|
+
|
54
|
+
Copyright (c) 2010 Christopher Meiklejohn
|
55
|
+
|
56
|
+
Permission is hereby granted, free of charge, to any person
|
57
|
+
obtaining a copy of this software and associated documentation
|
58
|
+
files (the "Software"), to deal in the Software without
|
59
|
+
restriction, including without limitation the rights to use,
|
60
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
61
|
+
copies of the Software, and to permit persons to whom the
|
62
|
+
Software is furnished to do so, subject to the following
|
63
|
+
conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice shall be
|
66
|
+
included in all copies or substantial portions of the Software.
|
67
|
+
|
68
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
69
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
70
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
71
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
72
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
73
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
74
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
75
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('wine_dot_com_api_request', '0.1.0') do |p|
|
6
|
+
p.description = "Provides an interface to the wine.com API."
|
7
|
+
p.url = "https://github.com/cmeiklejohn/wine_dot_com_api_request"
|
8
|
+
p.author = "Christopher Meiklejohn"
|
9
|
+
p.email = "cmeik@me.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
15
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'wine_dot_com_api_request'
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# WineDotComApiRequest class.
|
4
|
+
#
|
5
|
+
# Provides an interface to access the Wine.com API.
|
6
|
+
#
|
7
|
+
# Author:: Christopher Meiklejohn (cmeik@me.com)
|
8
|
+
# Copyright:: Copyright (c) 2010 Christopher Meiklejohn
|
9
|
+
# License:: Distributes under the terms specified in the MIT-LICENSE file.
|
10
|
+
#
|
11
|
+
# Usage example:
|
12
|
+
#w = WineDotComApiRequest.new(:search => 'mondavi cabernet',
|
13
|
+
# :format => :xml,
|
14
|
+
# :resource => :catalog,
|
15
|
+
# :size => 1,
|
16
|
+
# :offset => 0)
|
17
|
+
#
|
18
|
+
# w.query
|
19
|
+
#
|
20
|
+
# To-do:
|
21
|
+
# * Build a better interface for filters
|
22
|
+
# * Build a better interface for sortBy
|
23
|
+
# * Implement affiliateId
|
24
|
+
# * Implement version, beta currently only supported
|
25
|
+
# * Extract out api key and base url into configuration parameters
|
26
|
+
#
|
27
|
+
# See: http://api.wine.com/wiki/2-catalog-queries
|
28
|
+
require "wine_dot_com_api_request/configuration"
|
29
|
+
require 'net/http'
|
30
|
+
require 'uri'
|
31
|
+
|
32
|
+
class WineDotComApiRequest
|
33
|
+
public
|
34
|
+
# API key from Wine.com.
|
35
|
+
attr_accessor :api_key
|
36
|
+
|
37
|
+
# API version number. Available API versions: v1.0, v2.3.
|
38
|
+
attr_accessor :version
|
39
|
+
|
40
|
+
# API result format. Available API formats: xml, json.
|
41
|
+
attr_accessor :format
|
42
|
+
|
43
|
+
# API requested resource. Available API resources: catalog, reference, categorymap.
|
44
|
+
attr_accessor :resource
|
45
|
+
|
46
|
+
# API parameters.
|
47
|
+
attr_accessor :parameters
|
48
|
+
|
49
|
+
# Base URL of API.
|
50
|
+
attr_accessor :base_url
|
51
|
+
|
52
|
+
# Affiliate ID for revenue sharing.
|
53
|
+
attr_accessor :affiliate_id
|
54
|
+
|
55
|
+
# Search offset to start at.
|
56
|
+
attr_accessor :offset
|
57
|
+
|
58
|
+
# Number of records to return.
|
59
|
+
attr_accessor :size
|
60
|
+
|
61
|
+
# Search terms.
|
62
|
+
attr_accessor :search
|
63
|
+
|
64
|
+
# Search filter. Ex. filter=categories(7155+124)+rating(85|100).
|
65
|
+
attr_accessor :filter
|
66
|
+
|
67
|
+
# Ship to state. Two letter abbrev. Ex. MA.
|
68
|
+
attr_accessor :state
|
69
|
+
|
70
|
+
# Sort key. Ex. sort=rating|ascending.
|
71
|
+
attr_accessor :sort
|
72
|
+
|
73
|
+
# In stock. Boolean search value.
|
74
|
+
attr_accessor :instock
|
75
|
+
|
76
|
+
# Inialize the required parameters, and setup the request defaults.
|
77
|
+
def initialize(options = {})
|
78
|
+
options.each_pair do |key, value|
|
79
|
+
self.send("#{key}=", value)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Return URL that request will be made to. Mainly for debugging purposes.
|
84
|
+
def url
|
85
|
+
api_url
|
86
|
+
end
|
87
|
+
|
88
|
+
# Execute a search. Returns either raw json or xml.
|
89
|
+
def query(options = {})
|
90
|
+
options.each_pair do |key, value|
|
91
|
+
self.send("#{key}=", value)
|
92
|
+
end
|
93
|
+
|
94
|
+
raise 'No API base URL provided.' unless @@base_url
|
95
|
+
raise 'No API key provided.' unless @@api_key
|
96
|
+
raise 'No resource specified.' unless @resource
|
97
|
+
raise 'No format specified.' unless @format
|
98
|
+
|
99
|
+
return do_get
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
# Perform GET request and return results.
|
104
|
+
def do_get
|
105
|
+
Net::HTTP.get(URI.parse(api_url))
|
106
|
+
end
|
107
|
+
|
108
|
+
# Generate the url to make the API call to.
|
109
|
+
def api_url
|
110
|
+
"#{@@base_url}/#{format}/#{resource}?apikey=#{@@api_key}#{parameters}"
|
111
|
+
end
|
112
|
+
|
113
|
+
# parameters overrides attribute reader and returns custom results based on resource type.
|
114
|
+
def parameters
|
115
|
+
url_params = ""
|
116
|
+
|
117
|
+
if @resource == :catalog
|
118
|
+
url_params += "&" + "offset=#{URI.escape(@offset.to_s)}" if @offset
|
119
|
+
url_params += "&" + "size=#{URI.escape(@size.to_s)}" if @size
|
120
|
+
url_params += "&" + "search=#{URI.escape(@search)}" if @search
|
121
|
+
url_params += "&" + "filter=#{URI.escape(@filter)}" if @filter
|
122
|
+
url_params += "&" + "state=#{URI.escape(@state)}" if @state
|
123
|
+
url_params += "&" + "sort=#{URI.escape(@sort)}" if @sort
|
124
|
+
url_params += "&" + "instock=#{@instock}" if @instock
|
125
|
+
elsif @resource == :categorymap
|
126
|
+
url_params += "&" + "filter=#{URI.escape(@filter)}" if @filter
|
127
|
+
url_params += "&" + "search=#{URI.escape(@search)}" if @search
|
128
|
+
elsif @resource == :reference
|
129
|
+
url_params += "&" + "filter=#{URI.escape(@filter)}" if @filter
|
130
|
+
end
|
131
|
+
|
132
|
+
return url_params
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{wine_dot_com_api_request}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Christopher Meiklejohn"]
|
9
|
+
s.date = %q{2010-01-02}
|
10
|
+
s.description = %q{Provides an interface to the wine.com API.}
|
11
|
+
s.email = %q{cmeik@me.com}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/wine_dot_com_api_request.rb", "lib/wine_dot_com_api_request/configuration.rb"]
|
13
|
+
s.files = ["MIT-LICENSE", "Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/wine_dot_com_api_request.rb", "lib/wine_dot_com_api_request/configuration.rb", "test/wine_dot_com_api_request_test.rb", "wine_dot_com_api_request.gemspec"]
|
14
|
+
s.homepage = %q{https://github.com/cmeiklejohn/wine_dot_com_api_request}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Wine_dot_com_api_request", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{wine_dot_com_api_request}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Provides an interface to the wine.com API.}
|
20
|
+
s.test_files = ["test/wine_dot_com_api_request_test.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wine_dot_com_api_request
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Meiklejohn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-02 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Provides an interface to the wine.com API.
|
17
|
+
email: cmeik@me.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- lib/wine_dot_com_api_request.rb
|
25
|
+
- lib/wine_dot_com_api_request/configuration.rb
|
26
|
+
files:
|
27
|
+
- MIT-LICENSE
|
28
|
+
- Manifest
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- init.rb
|
32
|
+
- lib/wine_dot_com_api_request.rb
|
33
|
+
- lib/wine_dot_com_api_request/configuration.rb
|
34
|
+
- test/wine_dot_com_api_request_test.rb
|
35
|
+
- wine_dot_com_api_request.gemspec
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: https://github.com/cmeiklejohn/wine_dot_com_api_request
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --line-numbers
|
43
|
+
- --inline-source
|
44
|
+
- --title
|
45
|
+
- Wine_dot_com_api_request
|
46
|
+
- --main
|
47
|
+
- README.rdoc
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "1.2"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project: wine_dot_com_api_request
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Provides an interface to the wine.com API.
|
69
|
+
test_files:
|
70
|
+
- test/wine_dot_com_api_request_test.rb
|