vaporizer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19931f1173bb1426c8d52d9e184c1c8205e430d8
4
+ data.tar.gz: a613dcdc751e1b90835e23709128859fb11050c6
5
+ SHA512:
6
+ metadata.gz: e1b558f5279c6976366d75e984d665918c9be861df3faef61c4255f774df97bf183f3dee17d39641e61a5b2d9ac8bf635a5d612eca4b5aee74c487a025d79405
7
+ data.tar.gz: 9c24aa296db539ee1e94f72d4ed26b09dfe29168b8d73bb814e59a0a19746906bf8b7e55ca48f3b5ee2fc585c5b8954799e20a4532d028887224f1bae8f2b96f
@@ -0,0 +1,28 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+
24
+ .DS_Store
25
+ secrets.yml
26
+ spec/fixtures/*.yml
27
+ spec/fixtures/strains/*.yml
28
+ spec/fixtures/locations/*.yml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vaporizer.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Nicolas Florentin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,127 @@
1
+ # Vaporizer
2
+
3
+ Gem under construction
4
+
5
+ Will cover all endpoints of new Leafly API
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'vaporizer'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vaporizer
20
+
21
+ ## Good to know
22
+
23
+ Some things to know before using this gem:
24
+ * This is my first gem, please be tolerant
25
+ * Leafly API is kind of inconsistent and do not respect rules of JSON API standard, that's not my fault
26
+ * Changes in Leafly API could break this gem, if it happens, do not hesitate to open an issue and I will fix it as fast as possible
27
+ * Vaporizer returns pure parsed JSON and do not wrap results with objects
28
+ * If you need more functionalities, do not hesitate to contact me and we will discuss it
29
+
30
+ ## Configuration
31
+
32
+ ```ruby
33
+ require 'vaporizer'
34
+
35
+ Vaporizer.configure do |config|
36
+ config.app_id = "YOUR_APP_ID"
37
+ config.app_key = "YOUR_APP_KEY"
38
+ config.timeout = 3 # timeout for the requests, optional, in seconds
39
+ end
40
+ ```
41
+ ## Usage examples
42
+
43
+ These examples are a bit minimalist but you can of course pass more arguments to the methods
44
+
45
+ ### Strains
46
+
47
+ **search**
48
+ ```ruby
49
+ Vaporizer::Strain.search(search: 'dream', page: 0, take: 10)
50
+ ```
51
+
52
+ **more complex search**
53
+ ```ruby
54
+ Vaporizer::Strain.search(
55
+ filters: {
56
+ flavors: ['blueberry'],
57
+ conditions: ['anxiety']
58
+ },
59
+ search: '',
60
+ page: 0, take: 10
61
+ )
62
+ ```
63
+
64
+ **details**
65
+ ```ruby
66
+ Vaporizer::Strain.details('la-confidential') # argument is a slug of strain's name
67
+ ```
68
+
69
+ **reviews**
70
+ ```ruby
71
+ Vaporizer::Strain.reviews('la-confidential', { page: 0, take: 3 })
72
+ ```
73
+
74
+ **review details**
75
+ ```ruby
76
+ Vaporizer::Strain.review_details('la-confidential', 2836) # 2nd argument is the review id
77
+ ```
78
+
79
+ **photos**
80
+ ```ruby
81
+ Vaporizer::Strain.photos('la-confidential', { page: 0, take: 4 })
82
+ ```
83
+
84
+ **availabilities**
85
+ ```ruby
86
+ Vaporizer::Strain.availabilities('la-confidential', { lat: 33.5, lon: -117.6 })
87
+ ```
88
+
89
+ ### Locations
90
+
91
+ **search**
92
+ ```ruby
93
+ Vaporizer::Location.search(latitude: 47.606, longitude: -122.333, page: 0, take: 5)
94
+ ```
95
+
96
+ **details**
97
+ ```ruby
98
+ Vaporizer::Location.details('papa-ganja')
99
+ ```
100
+
101
+ **menu**
102
+ ```ruby
103
+ Vaporizer::Location.menu('papa-ganja')
104
+ ```
105
+
106
+ **reviews**
107
+ ```ruby
108
+ Vaporizer::Location.reviews('papa-ganja', { take: 3, skip: 0})
109
+ ```
110
+
111
+ **specials**
112
+ ```ruby
113
+ Vaporizer::Location.specials('papa-ganja')
114
+ ```
115
+
116
+ ## More options
117
+
118
+ To have the list of all params and filters available of the Leafly API, please refer to
119
+ the <a href="https://developer.leafly.com/docs">official documentation</a>
120
+
121
+ ## Contributing
122
+
123
+ 1. Fork it ( https://github.com/[my-github-username]/vaporizer/fork )
124
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
125
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
126
+ 4. Push to the branch (`git push origin my-new-feature`)
127
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,33 @@
1
+ require 'vaporizer/strain'
2
+ require 'vaporizer/location'
3
+ require 'vaporizer/http_client'
4
+ require 'vaporizer/validatable'
5
+ require 'vaporizer/version'
6
+ require 'vaporizer/error'
7
+
8
+ module Vaporizer
9
+
10
+ class << self
11
+ attr_accessor :config
12
+ end
13
+
14
+ def self.configure
15
+ self.config ||= Config.new
16
+ yield config
17
+ end
18
+
19
+ class Config
20
+ attr_accessor :app_id, :app_key
21
+
22
+ def timeout=(sec)
23
+ Vaporizer::HttpClient.module_eval do
24
+ default_timeout sec
25
+ end
26
+ end
27
+
28
+ def initialize
29
+ @app_id = ""
30
+ @app_key = ""
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ module Vaporizer
2
+ class Error < StandardError; end
3
+
4
+ class ServerError < Error; end
5
+ class NotFound < ServerError; end
6
+
7
+ class ClientError < Error; end
8
+ class MissingPathParameter < Error; end
9
+ class MissingParameter < Error; end
10
+ end
@@ -0,0 +1,76 @@
1
+ require 'httparty'
2
+
3
+ module Vaporizer
4
+ module HttpClient
5
+ include HTTParty
6
+
7
+ default_timeout 1
8
+ base_uri 'http://data.leafly.com'
9
+ headers 'Accept' => 'application/json', 'Accept-Encoding' => 'gzip, deflate'
10
+
11
+ def define_httparty_request_wrapper(name, method, route, extra_headers = {})
12
+ splited_route = split_route(route)
13
+ route_params_defined = extract_params_from_route(splited_route)
14
+ sub_paths = splited_route - route_params_defined
15
+
16
+ route_params_defined = strip_symbolize_route_params(route_params_defined)
17
+
18
+ define_singleton_method name do |params_given = {}, query_params = {}|
19
+ headers = { 'app_id' => Vaporizer.config.app_id,
20
+ 'app_key' => Vaporizer.config.app_key
21
+ }.merge(extra_headers)
22
+
23
+ opts = { headers: headers }.merge(query_params)
24
+
25
+ params_values = get_route_params_values(route_params_defined, params_given)
26
+ built_path = build_path(sub_paths, params_values)
27
+
28
+ response = Vaporizer::HttpClient.send(method, built_path, opts)
29
+ handle_response(response)
30
+ end
31
+ end
32
+
33
+ def get_route_params_values(url_params, params_given)
34
+ params_values = []
35
+ url_params.each do |param|
36
+ if !params_given.keys.include?(param)
37
+ raise Vaporizer::MissingPathParameter, "Path parameter #{param} is missing"
38
+ else
39
+ params_values << params_given[param]
40
+ end
41
+ end
42
+ params_values
43
+ end
44
+
45
+ private
46
+ def handle_response(response)
47
+ if response.not_found?
48
+ raise Vaporizer::NotFound, "#{response.code}"
49
+ elsif response.client_error?
50
+ raise Vaporizer::ClientError, "#{response.code}"
51
+ elsif response.server_error?
52
+ raise Vaporizer::ServerError, "#{response.code}"
53
+ elsif response.success?
54
+ response.parsed_response
55
+ else
56
+ raise Vaporizer::Error, "#{response.code}"
57
+ end
58
+ end
59
+
60
+ def build_path(sub_paths, params_values)
61
+ sub_paths.zip(params_values).flatten.compact.join
62
+ end
63
+
64
+ def strip_symbolize_route_params(params_array)
65
+ params_array.map { |param| param[1..-1].to_sym }
66
+ end
67
+
68
+ def split_route(route)
69
+ route.split(/(:[a-z_]+)/)
70
+ end
71
+
72
+ def extract_params_from_route(splited_path)
73
+ splited_path.select { |e| e[0] == ':' }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,39 @@
1
+ require 'vaporizer/http_client'
2
+ require 'vaporizer/validatable'
3
+
4
+ module Vaporizer
5
+ module Location
6
+ extend Vaporizer::HttpClient
7
+ extend Vaporizer::Validatable
8
+
9
+ define_httparty_request_wrapper :locations_search, :post, '/locations'
10
+ define_httparty_request_wrapper :locations_show, :get, '/locations/:slug'
11
+ define_httparty_request_wrapper :locations_menu_index, :get, '/locations/:slug/menu'
12
+ define_httparty_request_wrapper :locations_reviews_index, :get, '/locations/:slug/reviews'
13
+ define_httparty_request_wrapper :locations_specials_index, :get, '/locations/:slug/specials'
14
+
15
+ def self.search(params = {})
16
+ validate_presence_of([:page, :take, :latitude, :longitude], params)
17
+ params = { body: params }
18
+ locations_search({}, params)
19
+ end
20
+
21
+ def self.details(slug)
22
+ locations_show(slug: slug)
23
+ end
24
+
25
+ def self.menu(slug)
26
+ locations_menu_index(slug: slug)
27
+ end
28
+
29
+ def self.reviews(slug, params = {})
30
+ validate_presence_of([:take, :skip], params)
31
+ params = { query: params }
32
+ locations_reviews_index({ slug: slug }, params)
33
+ end
34
+
35
+ def self.specials(slug)
36
+ locations_specials_index({ slug: slug})
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,48 @@
1
+ require 'vaporizer/http_client'
2
+ require 'vaporizer/validatable'
3
+
4
+ module Vaporizer
5
+ module Strain
6
+ extend Vaporizer::HttpClient
7
+ extend Vaporizer::Validatable
8
+
9
+ define_httparty_request_wrapper :strains_search, :post, '/strains'
10
+ define_httparty_request_wrapper :strains_show, :get, '/strains/:slug'
11
+ define_httparty_request_wrapper :strains_reviews_index, :get, '/strains/:slug/reviews'
12
+ define_httparty_request_wrapper :strains_reviews_show, :get, '/strains/:slug/reviews/:review_id'
13
+ define_httparty_request_wrapper :strains_photos_index, :get, '/strains/:slug/photos'
14
+ define_httparty_request_wrapper :strains_availabilities_index, :get, '/strains/:slug/availability'
15
+
16
+ def self.search(params = {})
17
+ validate_presence_of([:page, :take], params)
18
+ params = { body: params.to_json }
19
+ strains_search({}, params)
20
+ end
21
+
22
+ def self.details(slug)
23
+ strains_show(slug: slug)
24
+ end
25
+
26
+ def self.reviews(slug, params = {})
27
+ validate_presence_of([:page, :take], params)
28
+ params = { query: params }
29
+ strains_reviews_index({ slug: slug }, params)
30
+ end
31
+
32
+ def self.review_details(slug, review_id)
33
+ strains_reviews_show({ slug: slug, review_id: review_id })
34
+ end
35
+
36
+ def self.photos(slug, params = {})
37
+ validate_presence_of([:page, :take], params)
38
+ params = { query: params }
39
+ strains_photos_index({ slug: slug }, params)
40
+ end
41
+
42
+ def self.availabilities(slug, params = {})
43
+ validate_presence_of([:lat, :lon], params)
44
+ params = { query: params }
45
+ strains_availabilities_index({ slug: slug }, params)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,13 @@
1
+ require 'vaporizer/error'
2
+
3
+ module Vaporizer
4
+ module Validatable
5
+ def validate_presence_of(keys, hash)
6
+ keys.each do |key|
7
+ unless hash.keys.include?(key)
8
+ raise Vaporizer::MissingParameter, "Missing param '#{key}'"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Vaporizer
2
+ VERSION = "0.1.0"
3
+ end
File without changes
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'webmock/rspec'
4
+ require 'vaporizer'
5
+
6
+ VCR.configure do |config|
7
+ config.debug_logger = $stderr
8
+ config.hook_into :webmock
9
+ config.cassette_library_dir = "spec/fixtures"
10
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vaporizer::HttpClient do
4
+ before :all do
5
+ @api = Module.new
6
+ @api.class.extend(Vaporizer::HttpClient)
7
+ @api = @api.class
8
+ end
9
+
10
+ describe 'get_route_params_values(url_params, params_given)' do
11
+ it "should return empty array if there are not url params" do
12
+ expect(@api.get_route_params_values([],{})).to eq([])
13
+ end
14
+ end
15
+
16
+ describe 'get_route_params_values(url_params, params_given)' do
17
+ context "there are no missing params" do
18
+ it "should return values of params values" do
19
+ expect(@api.get_route_params_values([:strain_id], { strain_id: '123' })).to eq(['123'])
20
+ end
21
+ end
22
+
23
+ context "there is missing param" do
24
+ it "should raise an error" do
25
+ expect { @api.get_route_params_values([:strain_id], {}) }.to raise_error(Vaporizer::MissingPathParameter)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "call define_httparty_request_wrapper at class level" do
31
+ before :all do
32
+ @api.class_eval do
33
+ define_httparty_request_wrapper :test_method, :get, '/testUrl/:test'
34
+ end
35
+ end
36
+
37
+ it "should define the method" do
38
+ expect(@api).to respond_to(:test_method)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,177 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ secrets = YAML.load_file('./secrets.yml')
5
+
6
+ describe Vaporizer::Location do
7
+
8
+ it { expect(Vaporizer::Location).to respond_to(:locations_search) }
9
+ it { expect(Vaporizer::Location).to respond_to(:locations_show) }
10
+ it { expect(Vaporizer::Location).to respond_to(:locations_menu_index) }
11
+ it { expect(Vaporizer::Location).to respond_to(:locations_reviews_index) }
12
+ it { expect(Vaporizer::Location).to respond_to(:locations_specials_index) }
13
+
14
+ before :all do
15
+ Vaporizer.configure do |config|
16
+ config.app_id = secrets['app_id']
17
+ config.app_key = secrets['app_key']
18
+ end
19
+
20
+ @location_slug = 'papa-ganja'
21
+
22
+ @non_existing_location_slug = "5d0e71bda1005d0770a4e31e1a27580"
23
+ VCR.use_cassette('locations/non-existing-details') do
24
+ begin
25
+ Vaporizer::Location.details(@non_existing_location_slug)
26
+ rescue Vaporizer::NotFound
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '.search(params = {})' do
32
+ context "valid params" do
33
+ before :all do
34
+ @take = 3
35
+ VCR.use_cassette('locations/search-valid_params') do
36
+ @locations = Vaporizer::Location.search(latitude: 47.606, longitude: -122.333, page: 0, take: @take)
37
+ end
38
+ end
39
+
40
+ it 'should return a hash' do
41
+ VCR.use_cassette('locations/search-valid_params') do
42
+ expect(@locations.class).to be(Hash)
43
+ end
44
+ end
45
+
46
+ it "should return a hash with a key named 'stores'" do
47
+ VCR.use_cassette('locations/search-valid_params') do
48
+ expect(@locations).to have_key('stores')
49
+ end
50
+ end
51
+ end
52
+
53
+ context "missing params" do
54
+ it "should raise error Vaporizer::MissingParameter" do
55
+ expect { Vaporizer::Location.search(search: '', longitude: -122.333, page: 0, take: @take) }.to raise_error(Vaporizer::MissingParameter)
56
+ end
57
+
58
+ it "should raise error Vaporizer::MissingParameter" do
59
+ expect { Vaporizer::Location.search(search: '', latitude: 47.606, page: 0) }.to raise_error(Vaporizer::MissingParameter)
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '.details(slug)' do
65
+ before :all do
66
+ VCR.use_cassette('locations/details') do
67
+ @location = Vaporizer::Location.details(@location_slug)
68
+ end
69
+ end
70
+
71
+ it 'should return a hash' do
72
+ VCR.use_cassette('locations/details') do
73
+ expect(@location.class).to be(Hash)
74
+ end
75
+ end
76
+
77
+ it "should return the specified store" do
78
+ VCR.use_cassette('locations/details') do
79
+ expect(@location['slug']).to eq(@location_slug)
80
+ end
81
+ end
82
+
83
+ it "should raise an error if store doesn't exist" do
84
+ expect do
85
+ VCR.use_cassette('locations/non-existing-details') do
86
+ Vaporizer::Location.details(@non_existing_location_slug)
87
+ end
88
+ end.to raise_error(Vaporizer::NotFound)
89
+ end
90
+ end
91
+
92
+ describe '.menu(slug)' do
93
+ before :all do
94
+ VCR.use_cassette('locations/menu') do
95
+ @menu = Vaporizer::Location.menu(@location_slug)
96
+ end
97
+ end
98
+
99
+ it 'should return a Array' do
100
+ VCR.use_cassette('locations/menu') do
101
+ expect(@menu.class).to be(Array)
102
+ end
103
+ end
104
+
105
+ it "should raise an error if store doesn't exist" do
106
+ expect do
107
+ VCR.use_cassette('locations/non-existing-menu') do
108
+ Vaporizer::Location.menu(@non_existing_location_slug)
109
+ end
110
+ end.to raise_error(Vaporizer::NotFound)
111
+ end
112
+ end
113
+
114
+ describe '.reviews(slug, params = {})' do
115
+ before :all do
116
+ VCR.use_cassette('locations/reviews') do
117
+ @reviews = Vaporizer::Location.reviews(@location_slug, { take: 1, skip: 0})
118
+ end
119
+ end
120
+
121
+ it 'should return a Array' do
122
+ VCR.use_cassette('locations/reviews') do
123
+ expect(@reviews.class).to be(Hash)
124
+ end
125
+ end
126
+
127
+ it 'should have key \'reviews\'' do
128
+ VCR.use_cassette('locations/reviews') do
129
+ expect(@reviews).to have_key('reviews')
130
+ end
131
+ end
132
+
133
+ it "should raise an error if store doesn't exist" do
134
+ expect do
135
+ VCR.use_cassette('locations/non-existing-reviews') do
136
+ Vaporizer::Location.reviews(@non_existing_location_slug, { take: 1, skip: 0})
137
+ end
138
+ end.to raise_error(Vaporizer::NotFound)
139
+ end
140
+
141
+ context "missing params" do
142
+ it "should raise error Vaporizer::MissingParameter" do
143
+ VCR.use_cassette('locations/reviews') do
144
+ expect { Vaporizer::Location.reviews(@location_slug, { take: 1}) }.to raise_error(Vaporizer::MissingParameter)
145
+ end
146
+ end
147
+
148
+ it "should raise error Vaporizer::MissingParameter" do
149
+ VCR.use_cassette('locations/reviews') do
150
+ expect { Vaporizer::Location.reviews(@location_slug, { skip: 0}) }.to raise_error(Vaporizer::MissingParameter)
151
+ end
152
+ end
153
+ end
154
+ end
155
+
156
+ describe '.specials(slug, params = {})' do
157
+ before :all do
158
+ VCR.use_cassette('locations/specials') do
159
+ @specials = Vaporizer::Location.specials(@location_slug)
160
+ end
161
+ end
162
+
163
+ it 'should return a Array' do
164
+ VCR.use_cassette('locations/specials') do
165
+ expect(@specials.class).to be(Array)
166
+ end
167
+ end
168
+
169
+ it "should raise an error if store doesn't exist" do
170
+ expect do
171
+ VCR.use_cassette('locations/non-existing-specials') do
172
+ Vaporizer::Location.specials(@non_existing_location_slug)
173
+ end
174
+ end.to raise_error(Vaporizer::NotFound)
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,336 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ secrets = YAML.load_file('./secrets.yml')
5
+
6
+ describe Vaporizer::Strain do
7
+
8
+ it { expect(Vaporizer::Strain).to respond_to(:strains_search) }
9
+ it { expect(Vaporizer::Strain).to respond_to(:strains_show) }
10
+ it { expect(Vaporizer::Strain).to respond_to(:strains_reviews_index) }
11
+ it { expect(Vaporizer::Strain).to respond_to(:strains_reviews_show) }
12
+ it { expect(Vaporizer::Strain).to respond_to(:strains_photos_index) }
13
+ it { expect(Vaporizer::Strain).to respond_to(:strains_availabilities_index) }
14
+
15
+ before :all do
16
+ Vaporizer.configure do |config|
17
+ config.app_id = secrets['app_id']
18
+ config.app_key = secrets['app_key']
19
+ end
20
+
21
+ @strain_slug = 'la-confidential'
22
+ @non_existing_strain_slug = "5d0e71bda1005d0770a4e31e1a27580d"
23
+
24
+ VCR.use_cassette('strains/non-existing-details') do
25
+ begin
26
+ Vaporizer::Strain.details(@non_existing_strain_slug)
27
+ rescue Vaporizer::NotFound
28
+ end
29
+ end
30
+
31
+ VCR.use_cassette('strains/non-existing-reviews') do
32
+ begin
33
+ Vaporizer::Strain.reviews(@non_existing_strain_slug, page: 0, take: 1)
34
+ rescue Vaporizer::NotFound
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '.search(params = {})' do
40
+ context "valid params" do
41
+ before :all do
42
+ @take = 10
43
+ VCR.use_cassette('strains/search-valid_params') do
44
+ @strains = Vaporizer::Strain.search(search: '', page: 0, take: @take)
45
+ end
46
+ end
47
+
48
+ it 'should return a hash' do
49
+ VCR.use_cassette('strains/search-valid_params') do
50
+ expect(@strains.class).to be(Hash)
51
+ end
52
+ end
53
+
54
+ it "should return a hash with a key named 'Strains'" do
55
+ VCR.use_cassette('strains/search-valid_params') do
56
+ expect(@strains).to have_key('Strains')
57
+ end
58
+ end
59
+
60
+ it "should return the right number of strains" do
61
+ VCR.use_cassette('strains/search-valid_params') do
62
+ expect(@strains['Strains'].size).to eq(@take)
63
+ end
64
+ end
65
+ end
66
+
67
+ context "missing params" do
68
+ it "should raise error Vaporizer::MissingParameter" do
69
+ expect { Vaporizer::Strain.search(search: '', page: 0) }.to raise_error(Vaporizer::MissingParameter)
70
+ end
71
+
72
+ it "should raise error Vaporizer::MissingParameter" do
73
+ expect { Vaporizer::Strain.search(search: '', take: 0) }.to raise_error(Vaporizer::MissingParameter)
74
+ end
75
+ end
76
+
77
+ context "a bit more complex search" do
78
+ before :all do
79
+ @flavor = 'blueberry'
80
+ @condition = 'anxiety'
81
+ VCR.use_cassette('strains/search-complex') do
82
+ @strains = Vaporizer::Strain.search(
83
+ filters: {
84
+ flavors: [@flavor],
85
+ conditions: [@condition]
86
+ },
87
+ search: '',
88
+ page: 0, take: 1
89
+ )
90
+ end
91
+ end
92
+
93
+ it 'should return a hash' do
94
+ VCR.use_cassette('strains/search-complex') do
95
+ expect(@strains.class).to be(Hash)
96
+ end
97
+ end
98
+
99
+ it "should return a hash with a key named 'Strains'" do
100
+ VCR.use_cassette('strains/search-complex') do
101
+ expect(@strains).to have_key('Strains')
102
+ end
103
+ end
104
+
105
+ it "should return strains with specified flavor" do
106
+ VCR.use_cassette('strains/search-complex') do
107
+ expect(
108
+ @strains["Strains"][0]['Flavors'].map { |flavor| flavor['Name'].downcase }
109
+ ).to include(@flavor)
110
+ end
111
+ end
112
+
113
+ it "should return strains with specified condition" do
114
+ VCR.use_cassette('strains/search-complex') do
115
+ expect(
116
+ @strains["Strains"][0]['Conditions'].map { |condition| condition['Name'].downcase }
117
+ ).to include(@condition)
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ describe '.details(slug)' do
124
+ before :all do
125
+ VCR.use_cassette('strains/details') do
126
+ @strain = Vaporizer::Strain.details(@strain_slug)
127
+ end
128
+ end
129
+
130
+ it 'should return a hash' do
131
+ VCR.use_cassette('strains/details') do
132
+ expect(@strain.class).to be(Hash)
133
+ end
134
+ end
135
+
136
+ it "should return the specified strain" do
137
+ VCR.use_cassette('strains/details') do
138
+ expect(@strain['slug']).to eq(@strain_slug)
139
+ end
140
+ end
141
+
142
+ it "should raise an error if strain doesn't exist" do
143
+ expect do
144
+ VCR.use_cassette('strains/non-existing-details') do
145
+ Vaporizer::Strain.details(@non_existing_strain_slug)
146
+ end
147
+ end.to raise_error(Vaporizer::NotFound)
148
+ end
149
+ end
150
+
151
+ describe '.reviews(slug, params = {})' do
152
+ context "valid params" do
153
+ before :all do
154
+ @take = 7
155
+ @page = 0
156
+ VCR.use_cassette('strains/reviews') do
157
+ @reviews = Vaporizer::Strain.reviews(@strain_slug, { page: @page, take: @take })
158
+ end
159
+ end
160
+
161
+ it 'should return a hash' do
162
+ VCR.use_cassette('strains/reviews') do
163
+ expect(@reviews.class).to be(Hash)
164
+ end
165
+ end
166
+
167
+ it "should return a hash with a key named 'reviews'" do
168
+ VCR.use_cassette('strains/reviews') do
169
+ expect(@reviews).to have_key('reviews')
170
+ end
171
+ end
172
+
173
+ it "should return the right number of reviews" do
174
+ VCR.use_cassette('strains/reviews') do
175
+ expect(@reviews['reviews'].size).to eq(@take)
176
+ end
177
+ end
178
+
179
+ it "should give paging context corresponding to sent params" do
180
+ VCR.use_cassette('strains/reviews') do
181
+ expect(@reviews['pagingContext']['PageIndex']).to eq(@page)
182
+ end
183
+ end
184
+
185
+ it "should give paging context corresponding to sent params" do
186
+ VCR.use_cassette('strains/reviews') do
187
+ expect(@reviews['pagingContext']['PageSize']).to eq(@take)
188
+ end
189
+ end
190
+
191
+ it "should raise an error if strain doesn't exist" do
192
+ expect do
193
+ VCR.use_cassette('strains/non-existing-reviews') do
194
+ Vaporizer::Strain.reviews(@non_existing_strain_slug, { page: 0, take: 1 })
195
+ end
196
+ end.to raise_error(Vaporizer::NotFound)
197
+ end
198
+ end
199
+
200
+ context "missing params" do
201
+ it "should raise error Vaporizer::MissingParameter" do
202
+ expect { Vaporizer::Strain.reviews(@strain_slug, { take: 2 }) }.to raise_error(Vaporizer::MissingParameter)
203
+ end
204
+
205
+ it "should raise error Vaporizer::MissingParameter" do
206
+ expect { Vaporizer::Strain.reviews(@strain_slug, { page: 1 }) }.to raise_error(Vaporizer::MissingParameter)
207
+ end
208
+ end
209
+ end
210
+
211
+ describe '.review_details(slug, review_id)' do
212
+ context "valid params" do
213
+ before :all do
214
+ @id = 2836
215
+ @strain_slug = @strain_slug
216
+ VCR.use_cassette('strains/review_details') do
217
+ @review = Vaporizer::Strain.review_details(@strain_slug, @id)
218
+ end
219
+ end
220
+
221
+ it 'should return a hash' do
222
+ VCR.use_cassette('strains/review_details') do
223
+ expect(@review.class).to be(Hash)
224
+ end
225
+ end
226
+
227
+ it 'should return the right review' do
228
+ VCR.use_cassette('strains/review_details') do
229
+ expect(@review['id']).to eq(@id)
230
+ end
231
+ end
232
+
233
+ it 'should correspond to the right strain' do
234
+ VCR.use_cassette('strains/review_details') do
235
+ expect(@review['strainSlug']).to eq(@strain_slug)
236
+ end
237
+ end
238
+ end
239
+ end
240
+
241
+ describe '.photos(slug, params = {})' do
242
+ context "valid params" do
243
+ before :all do
244
+ @take = 7
245
+ @page = 0
246
+ VCR.use_cassette('strains/photos') do
247
+ @photos = Vaporizer::Strain.photos(@strain_slug, { page: @page, take: @take })
248
+ end
249
+ end
250
+
251
+ it 'should return a hash' do
252
+ VCR.use_cassette('strains/photos') do
253
+ expect(@photos.class).to be(Hash)
254
+ end
255
+ end
256
+
257
+ it "should return a hash with a key named 'photos'" do
258
+ VCR.use_cassette('strains/photos') do
259
+ expect(@photos).to have_key('photos')
260
+ end
261
+ end
262
+
263
+ it "should return the right number of reviews" do
264
+ VCR.use_cassette('strains/photos') do
265
+ expect(@photos['photos'].size).to eq(@take)
266
+ end
267
+ end
268
+
269
+ it "should give paging context corresponding to sent params" do
270
+ VCR.use_cassette('strains/photos') do
271
+ expect(@photos['pagingContext']['PageIndex']).to eq(@page)
272
+ end
273
+ end
274
+
275
+ it "should give paging context corresponding to sent params" do
276
+ VCR.use_cassette('strains/photos') do
277
+ expect(@photos['pagingContext']['PageSize']).to eq(@take)
278
+ end
279
+ end
280
+
281
+ context "missing params" do
282
+ it "should raise error Vaporizer::MissingParameter" do
283
+ expect { Vaporizer::Strain.photos(@strain_slug, { take: 2 }) }.to raise_error(Vaporizer::MissingParameter)
284
+ end
285
+
286
+ it "should raise error Vaporizer::MissingParameter" do
287
+ expect { Vaporizer::Strain.photos(@strain_slug, { page: 1 }) }.to raise_error(Vaporizer::MissingParameter)
288
+ end
289
+ end
290
+
291
+ it "should raise an error if strain doesn't exist" do
292
+ expect do
293
+ VCR.use_cassette('strains/non-existing-photos') do
294
+ Vaporizer::Strain.photos(@non_existing_strain_slug, { page: 0, take: 1 })
295
+ end
296
+ end.to raise_error(Vaporizer::NotFound)
297
+ end
298
+ end
299
+ end
300
+
301
+ describe '.availabilities(slug, params = {})' do
302
+ context "valid params" do
303
+ before :all do
304
+ @take = 7
305
+ @page = 0
306
+ VCR.use_cassette('strains/availabilities') do
307
+ @availabilities = Vaporizer::Strain.availabilities(@strain_slug, { lat: 50, lon: 50 })
308
+ end
309
+ end
310
+
311
+ it 'should return an array' do
312
+ VCR.use_cassette('strains/availabilities') do
313
+ expect(@availabilities.class).to be(Array)
314
+ end
315
+ end
316
+
317
+ context "missing params" do
318
+ it "should raise error Vaporizer::MissingParameter" do
319
+ expect { Vaporizer::Strain.availabilities(@strain_slug, { lat: 0 }) }.to raise_error(Vaporizer::MissingParameter)
320
+ end
321
+
322
+ it "should raise error Vaporizer::MissingParameter" do
323
+ expect { Vaporizer::Strain.availabilities(@strain_slug, { lon: 0 }) }.to raise_error(Vaporizer::MissingParameter)
324
+ end
325
+ end
326
+
327
+ it "should raise error if strain doesn't exist" do
328
+ expect do
329
+ VCR.use_cassette('strains/non-existing-availabilities') do
330
+ Vaporizer::Strain.availabilities(@non_existing_strain_slug, { lat: 0, lon: 0 })
331
+ end
332
+ end.to raise_error(Vaporizer::NotFound)
333
+ end
334
+ end
335
+ end
336
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vaporizer do
4
+ it { expect(Vaporizer).to respond_to(:configure) }
5
+
6
+ context "after configure" do
7
+ before :all do
8
+ Vaporizer.configure do |config|
9
+ end
10
+ end
11
+
12
+ it { expect(Vaporizer.config).to respond_to(:app_key) }
13
+ it { expect(Vaporizer.config).to respond_to(:app_id) }
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vaporizer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vaporizer"
8
+ spec.version = Vaporizer::VERSION
9
+ spec.authors = ["Nicolas Florentin"]
10
+ spec.email = ["nf.florentin@gmail.com"]
11
+ spec.summary = 'A lightweight ruby wrapper to consume Leafly API'
12
+ spec.description = 'Vaporizer is a lightweight ruby wrapper which enable to consume easily the new Leafly API which needs authentication'
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'vcr'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'webmock'
26
+
27
+ spec.add_runtime_dependency('json')
28
+ spec.add_runtime_dependency('httparty')
29
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vaporizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Florentin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: vcr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Vaporizer is a lightweight ruby wrapper which enable to consume easily
112
+ the new Leafly API which needs authentication
113
+ email:
114
+ - nf.florentin@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/vaporizer.rb
125
+ - lib/vaporizer/error.rb
126
+ - lib/vaporizer/http_client.rb
127
+ - lib/vaporizer/location.rb
128
+ - lib/vaporizer/strain.rb
129
+ - lib/vaporizer/validatable.rb
130
+ - lib/vaporizer/version.rb
131
+ - spec/fixtures/.gitkeep
132
+ - spec/spec_helper.rb
133
+ - spec/vaporizer/http_client_spec.rb
134
+ - spec/vaporizer/location_spec.rb
135
+ - spec/vaporizer/strain_spec.rb
136
+ - spec/vaporizer_spec.rb
137
+ - vaporizer.gemspec
138
+ homepage: ''
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.4.5
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: A lightweight ruby wrapper to consume Leafly API
162
+ test_files:
163
+ - spec/fixtures/.gitkeep
164
+ - spec/spec_helper.rb
165
+ - spec/vaporizer/http_client_spec.rb
166
+ - spec/vaporizer/location_spec.rb
167
+ - spec/vaporizer/strain_spec.rb
168
+ - spec/vaporizer_spec.rb