vast_api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source "http://rubygems.org"
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "activesupport", ">= 2.3.5"
6
6
  gem "nokogiri", ">= 0"
7
-
7
+ gem 'typhoeus'
8
8
  # Add dependencies to develop your gem here.
9
9
  # Include everything needed to run rake, tests, features, etc.
10
10
  group :development do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,8 +1,7 @@
1
- require 'open-uri'
2
1
  require 'nokogiri'
3
2
  require 'builder'
4
3
  require 'active_support'
5
- require 'net/http'
4
+ require 'typhoeus'
6
5
  begin
7
6
  require 'active_support/core_ext/object/to_query'
8
7
  require 'active_support/core_ext/module/delegation'
@@ -20,8 +19,9 @@ require File.expand_path('../vast_api/listings/entry.rb', __FILE__)
20
19
  class VastApi
21
20
  attr_accessor :api_url, :light
22
21
 
23
- def initialize(apikey=nil, cat=nil)
24
- @api_url = 'http://data.vast.com/'
22
+ def initialize(apikey=nil, cat=nil, opts = {})
23
+ @api_url = opts[:api_url] || 'http://data.vast.com/'
24
+ @light = opts[:light] || false
25
25
  @category = cat
26
26
  @query = { }
27
27
  @query['apikey'] = apikey if apikey
@@ -61,7 +61,13 @@ class VastApi
61
61
  end
62
62
 
63
63
  def query
64
- @query.to_query
64
+ q = @query.dup
65
+ if light
66
+ q['light'] = 'yes'
67
+ else
68
+ q.delete('light')
69
+ end
70
+ q.to_query
65
71
  end
66
72
 
67
73
  def api_query
@@ -1,6 +1,6 @@
1
1
  class VastApi
2
2
  class Attributes < Hash
3
- attr_reader :xml, :url, :vast
3
+ attr_reader :response, :xml, :url, :vast
4
4
 
5
5
  def listings
6
6
  @listings ||= vast.listings
@@ -9,7 +9,8 @@ class VastApi
9
9
  def initialize(vast)
10
10
  @vast = vast
11
11
  @url = "#{@vast.api_url}attributes/-/#{@vast.category}?#{@vast.query}"
12
- @xml = Nokogiri::XML(open(@url))
12
+ @response = Typhoeus::Request.get(@url)
13
+ @xml = Nokogiri::XML(@response.body)
13
14
  populate
14
15
  end
15
16
 
@@ -1,13 +1,14 @@
1
1
  class VastApi
2
2
  class Categories < Hash
3
- attr_reader :xml, :url, :vast
3
+ attr_reader :response,:xml, :url, :vast
4
4
 
5
5
  delegate :attributes, :listings, :categories, :to=>:vast
6
6
 
7
7
  def initialize(vast)
8
8
  @vast = vast
9
9
  @url = "#{@vast.api_url}categories?#{@vast.api_query}"
10
- @xml = Nokogiri::XML(open(@url))
10
+ @response = Typhoeus::Request.get(@url)
11
+ @xml = Nokogiri::XML(@response.body)
11
12
  populate
12
13
  end
13
14
 
@@ -1,13 +1,14 @@
1
1
  class VastApi
2
2
  class Listings < Array
3
- attr_reader :xml, :url, :vast, :attributes
3
+ attr_reader :response, :xml, :url, :vast, :attributes
4
4
 
5
5
  delegate :find, :find!, :to=>:vast
6
6
 
7
7
  def initialize(vast)
8
8
  @vast = vast
9
9
  @url = "#{@vast.api_url}listings/-/#{@vast.category}?#{@vast.query}"
10
- @xml = Nokogiri::XML(open(@url))
10
+ @response = Typhoeus::Request.get(@url)
11
+ @xml = Nokogiri::XML(@response.body)
11
12
  populate
12
13
  end
13
14
 
@@ -34,7 +35,8 @@ class VastApi
34
35
  end
35
36
 
36
37
  def self.get(vast,url)
37
- Entry.new(vast, Nokogiri::XML(open(url)).at('entry'))
38
+ response = Typhoeus::Request.get(url)
39
+ Entry.new(vast, Nokogiri::XML(response.body).at('entry'))
38
40
  end
39
41
 
40
42
  def attributes
@@ -23,7 +23,7 @@ class VastApi
23
23
  vast_links
24
24
  @doc.children.each do |item|
25
25
  next if item.name == 'links'
26
- if %W{id author link feeds updated published}.index(var_name)
26
+ if %W{id author link feeds updated published}.index(item.name)
27
27
  self.send(var_name)
28
28
  else
29
29
  @attributes[item.name] ||= item.content
@@ -88,19 +88,19 @@ class VastApi
88
88
  {
89
89
  "customer" =>
90
90
  {
91
- "comments" => params[:comments] || "",
91
+ "comments" => params["comments"] || "",
92
92
  "contact" =>
93
93
  {
94
- "phone" => params[:phone] || "",
94
+ "phone" => params["phone"] || "",
95
95
  "address" =>
96
96
  {
97
- "street_1" => params[:street_1] || "",
98
- "regioncode" => params[:regioncode] || "",
99
- "postalcode" => params[:postalcode] || "",
100
- "city" => params[:city]} || "",
101
- "email" => params[:email] || "",
102
- "name_last" => params[:name_last] || "",
103
- "name_first" => params[:name_first] || ""
97
+ "street_1" => params["street_1"] || "",
98
+ "regioncode" => params["regioncode"] || "",
99
+ "postalcode" => params["postalcode"] || "",
100
+ "city" => params["city"]} || "",
101
+ "email" => params["email"] || "",
102
+ "name_last" => params["name_last"] || "",
103
+ "name_first" => params["name_first"] || ""
104
104
  }
105
105
  }
106
106
  }
@@ -19,3 +19,23 @@
19
19
  body: ! "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<status code=\"401\" type=\"authorization\">\n\t<message>Unauthorized
20
20
  Access - Bad API Key</message>\n</status>\n\n"
21
21
  http_version: '1.1'
22
+ - !ruby/struct:VCR::HTTPInteraction
23
+ request: !ruby/struct:VCR::Request
24
+ method: :get
25
+ uri: http://leads.vast.com:80/leads/schema/6268881899028898162/-/item_vehicle/bike?apikey=
26
+ body: !!null
27
+ headers: !!null
28
+ response: !ruby/struct:VCR::Response
29
+ status: !ruby/struct:VCR::ResponseStatus
30
+ code: 401
31
+ message: Unauthorized
32
+ headers:
33
+ content-type:
34
+ - text/xml; charset=iso-8859-1
35
+ content-length:
36
+ - '145'
37
+ server:
38
+ - Jetty(6.1.3)
39
+ body: ! "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<status code=\"401\" type=\"authorization\">\n\t<message>Unauthorized
40
+ Access - Bad API Key</message>\n</status>\n\n"
41
+ http_version: '1.1'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{vast_api}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Ryan Ong}, %q{Mikhail Knyazev}]
12
- s.date = %q{2011-08-12}
12
+ s.date = %q{2011-08-22}
13
13
  s.description = %q{A ruby wrapper for the http://www.vast.com/ api}
14
14
  s.email = %q{ryanong@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -56,6 +56,7 @@ Gem::Specification.new do |s|
56
56
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
57
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
58
58
  s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
59
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
59
60
  s.add_development_dependency(%q<minitest>, [">= 0"])
60
61
  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
61
62
  s.add_development_dependency(%q<bundler>, [">= 0"])
@@ -68,6 +69,7 @@ Gem::Specification.new do |s|
68
69
  else
69
70
  s.add_dependency(%q<activesupport>, [">= 2.3.5"])
70
71
  s.add_dependency(%q<nokogiri>, [">= 0"])
72
+ s.add_dependency(%q<typhoeus>, [">= 0"])
71
73
  s.add_dependency(%q<minitest>, [">= 0"])
72
74
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
73
75
  s.add_dependency(%q<bundler>, [">= 0"])
@@ -81,6 +83,7 @@ Gem::Specification.new do |s|
81
83
  else
82
84
  s.add_dependency(%q<activesupport>, [">= 2.3.5"])
83
85
  s.add_dependency(%q<nokogiri>, [">= 0"])
86
+ s.add_dependency(%q<typhoeus>, [">= 0"])
84
87
  s.add_dependency(%q<minitest>, [">= 0"])
85
88
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
86
89
  s.add_dependency(%q<bundler>, [">= 0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vast_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-08-12 00:00:00.000000000Z
13
+ date: 2011-08-22 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2151936060 !ruby/object:Gem::Requirement
17
+ requirement: &2158338480 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.3.5
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2151936060
25
+ version_requirements: *2158338480
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: nokogiri
28
- requirement: &2151933120 !ruby/object:Gem::Requirement
28
+ requirement: &2158338000 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,21 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2151933120
36
+ version_requirements: *2158338000
37
+ - !ruby/object:Gem::Dependency
38
+ name: typhoeus
39
+ requirement: &2158337520 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2158337520
37
48
  - !ruby/object:Gem::Dependency
38
49
  name: minitest
39
- requirement: &2151928560 !ruby/object:Gem::Requirement
50
+ requirement: &2158337040 !ruby/object:Gem::Requirement
40
51
  none: false
41
52
  requirements:
42
53
  - - ! '>='
@@ -44,10 +55,10 @@ dependencies:
44
55
  version: '0'
45
56
  type: :development
46
57
  prerelease: false
47
- version_requirements: *2151928560
58
+ version_requirements: *2158337040
48
59
  - !ruby/object:Gem::Dependency
49
60
  name: yard
50
- requirement: &2151923220 !ruby/object:Gem::Requirement
61
+ requirement: &2158336560 !ruby/object:Gem::Requirement
51
62
  none: false
52
63
  requirements:
53
64
  - - ~>
@@ -55,10 +66,10 @@ dependencies:
55
66
  version: 0.6.0
56
67
  type: :development
57
68
  prerelease: false
58
- version_requirements: *2151923220
69
+ version_requirements: *2158336560
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: bundler
61
- requirement: &2151918800 !ruby/object:Gem::Requirement
72
+ requirement: &2158336080 !ruby/object:Gem::Requirement
62
73
  none: false
63
74
  requirements:
64
75
  - - ! '>='
@@ -66,10 +77,10 @@ dependencies:
66
77
  version: '0'
67
78
  type: :development
68
79
  prerelease: false
69
- version_requirements: *2151918800
80
+ version_requirements: *2158336080
70
81
  - !ruby/object:Gem::Dependency
71
82
  name: jeweler
72
- requirement: &2151912820 !ruby/object:Gem::Requirement
83
+ requirement: &2158335600 !ruby/object:Gem::Requirement
73
84
  none: false
74
85
  requirements:
75
86
  - - ~>
@@ -77,10 +88,10 @@ dependencies:
77
88
  version: 1.5.2
78
89
  type: :development
79
90
  prerelease: false
80
- version_requirements: *2151912820
91
+ version_requirements: *2158335600
81
92
  - !ruby/object:Gem::Dependency
82
93
  name: rcov
83
- requirement: &2151906900 !ruby/object:Gem::Requirement
94
+ requirement: &2158335120 !ruby/object:Gem::Requirement
84
95
  none: false
85
96
  requirements:
86
97
  - - ! '>='
@@ -88,10 +99,10 @@ dependencies:
88
99
  version: '0'
89
100
  type: :development
90
101
  prerelease: false
91
- version_requirements: *2151906900
102
+ version_requirements: *2158335120
92
103
  - !ruby/object:Gem::Dependency
93
104
  name: webmock
94
- requirement: &2151903840 !ruby/object:Gem::Requirement
105
+ requirement: &2158334640 !ruby/object:Gem::Requirement
95
106
  none: false
96
107
  requirements:
97
108
  - - ! '>='
@@ -99,10 +110,10 @@ dependencies:
99
110
  version: '0'
100
111
  type: :development
101
112
  prerelease: false
102
- version_requirements: *2151903840
113
+ version_requirements: *2158334640
103
114
  - !ruby/object:Gem::Dependency
104
115
  name: vcr
105
- requirement: &2151900960 !ruby/object:Gem::Requirement
116
+ requirement: &2158334160 !ruby/object:Gem::Requirement
106
117
  none: false
107
118
  requirements:
108
119
  - - ! '>='
@@ -110,10 +121,10 @@ dependencies:
110
121
  version: '0'
111
122
  type: :development
112
123
  prerelease: false
113
- version_requirements: *2151900960
124
+ version_requirements: *2158334160
114
125
  - !ruby/object:Gem::Dependency
115
126
  name: i18n
116
- requirement: &2151898040 !ruby/object:Gem::Requirement
127
+ requirement: &2158350040 !ruby/object:Gem::Requirement
117
128
  none: false
118
129
  requirements:
119
130
  - - ! '>='
@@ -121,10 +132,10 @@ dependencies:
121
132
  version: '0'
122
133
  type: :development
123
134
  prerelease: false
124
- version_requirements: *2151898040
135
+ version_requirements: *2158350040
125
136
  - !ruby/object:Gem::Dependency
126
137
  name: builder
127
- requirement: &2151890900 !ruby/object:Gem::Requirement
138
+ requirement: &2158349560 !ruby/object:Gem::Requirement
128
139
  none: false
129
140
  requirements:
130
141
  - - ! '>='
@@ -132,7 +143,7 @@ dependencies:
132
143
  version: '0'
133
144
  type: :development
134
145
  prerelease: false
135
- version_requirements: *2151890900
146
+ version_requirements: *2158349560
136
147
  description: A ruby wrapper for the http://www.vast.com/ api
137
148
  email: ryanong@gmail.com
138
149
  executables: []
@@ -178,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
189
  version: '0'
179
190
  segments:
180
191
  - 0
181
- hash: -792478915482862852
192
+ hash: -1120050446381631647
182
193
  required_rubygems_version: !ruby/object:Gem::Requirement
183
194
  none: false
184
195
  requirements: