hungry 0.1.1 → 0.1.2
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.
- checksums.yaml +5 -5
- data/.travis.yml +0 -3
- data/Gemfile.lock +1 -1
- data/Rakefile +2 -2
- data/hungry.gemspec +3 -6
- data/lib/hungry.rb +12 -14
- data/lib/hungry/city.rb +2 -2
- data/lib/hungry/collection.rb +22 -22
- data/lib/hungry/country.rb +2 -2
- data/lib/hungry/geolocation.rb +15 -15
- data/lib/hungry/location.rb +9 -9
- data/lib/hungry/menu.rb +15 -15
- data/lib/hungry/menu/category.rb +4 -4
- data/lib/hungry/menu/dish.rb +4 -4
- data/lib/hungry/menu/option.rb +2 -2
- data/lib/hungry/region.rb +2 -2
- data/lib/hungry/resource.rb +49 -35
- data/lib/hungry/response.rb +6 -6
- data/lib/hungry/review.rb +7 -7
- data/lib/hungry/site.rb +13 -12
- data/lib/hungry/tag.rb +7 -7
- data/lib/hungry/user.rb +21 -21
- data/lib/hungry/util.rb +13 -13
- data/lib/hungry/venue.rb +22 -22
- data/lib/hungry/venue/collection.rb +9 -9
- data/lib/support/presence.rb +1 -1
- data/spec/hungry/geolocation_spec.rb +20 -20
- data/spec/hungry/util_spec.rb +9 -9
- metadata +3 -4
data/lib/hungry/util.rb
CHANGED
@@ -3,52 +3,52 @@ require 'cgi' unless defined?(CGI)
|
|
3
3
|
module Hungry
|
4
4
|
module Util
|
5
5
|
extend self
|
6
|
-
|
6
|
+
|
7
7
|
def log(message, type = :info)
|
8
8
|
if Hungry.logger
|
9
9
|
message = "[Hungry] #{message}"
|
10
10
|
Hungry.logger.send(type, message)
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def parse_json(json)
|
15
15
|
Hungry.json_parser.call(json)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def params_from_uri(uri)
|
19
19
|
uri = URI.parse(uri) unless uri.is_a?(URI)
|
20
20
|
parse_query(uri.query) if uri.query.present?
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def uri_with_params(uri, params = {})
|
24
24
|
params = params.map { |k,v| "#{k}=#{CGI.escape(v.to_s)}" }
|
25
25
|
.join('&')
|
26
26
|
.presence
|
27
|
-
|
27
|
+
|
28
28
|
[uri, params].compact
|
29
29
|
.join('?')
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def is_numeric?(value)
|
33
33
|
!!(value.to_s =~ /^[+-]?[\d]+(\.[\d]+){0,1}$/)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
private
|
37
|
-
|
37
|
+
|
38
38
|
# Copied from rack/utils:
|
39
39
|
def unescape(s, encoding = Encoding::UTF_8)
|
40
40
|
URI.decode_www_form_component(s, encoding)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def parse_query(qs, d = nil, &unescaper)
|
44
44
|
unescaper ||= method(:unescape)
|
45
|
-
|
45
|
+
|
46
46
|
params = {}
|
47
|
-
|
47
|
+
|
48
48
|
(qs || '').split(d ? /[#{d}] */ : /[&;] */n).each do |p|
|
49
49
|
next if p.empty?
|
50
50
|
k, v = p.split('=', 2).map(&unescaper)
|
51
|
-
|
51
|
+
|
52
52
|
if cur = params[k]
|
53
53
|
if cur.class == Array
|
54
54
|
params[k] << v
|
@@ -59,7 +59,7 @@ module Hungry
|
|
59
59
|
params[k] = v
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
params
|
64
64
|
end
|
65
65
|
end
|
data/lib/hungry/venue.rb
CHANGED
@@ -1,72 +1,72 @@
|
|
1
1
|
module Hungry
|
2
2
|
class Venue < Resource
|
3
3
|
autoload :Collection, 'hungry/venue/collection'
|
4
|
-
|
4
|
+
|
5
5
|
self.endpoint = '/venues'
|
6
|
-
|
6
|
+
|
7
7
|
### RESOURCES:
|
8
|
-
|
8
|
+
|
9
9
|
has_many :reviews, 'Hungry::Review'
|
10
|
-
|
10
|
+
|
11
11
|
belongs_to :country, 'Hungry::Country'
|
12
|
-
|
12
|
+
|
13
13
|
belongs_to :region, 'Hungry::Region'
|
14
|
-
|
14
|
+
|
15
15
|
belongs_to :city, 'Hungry::City'
|
16
|
-
|
16
|
+
|
17
17
|
### FINDERS:
|
18
|
-
|
18
|
+
|
19
19
|
def self.collection
|
20
20
|
Collection.new(self, endpoint, default_criteria)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def self.search(query)
|
24
24
|
collection.search(query)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def self.nearby(geolocation, options = {})
|
28
28
|
collection.nearby(geolocation, options)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def self.tagged_with(*tags)
|
32
32
|
collection.tagged_with(*tags)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def self.sort_by(sortable)
|
36
36
|
collection.sort_by(sortable)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def self.maintainable_by(user_or_id)
|
40
40
|
collection.maintainable_by(user_or_id)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def self.paginate(page, options = {})
|
44
44
|
collection.paginate(page, options)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
### ATTRIBUTES:
|
48
|
-
|
48
|
+
|
49
49
|
### Preview:
|
50
50
|
attr_accessor :id, :name, :category, :telephone, :fax, :website_url,
|
51
|
-
:tagline, :rating, :url, :address, :geolocation,
|
51
|
+
:tagline, :rating, :url, :address, :geolocation,
|
52
52
|
:currency_symbol, :relevance, :distance, :plan,
|
53
|
-
|
53
|
+
|
54
54
|
### Full:
|
55
55
|
:reachability, :staff, :prices, :capacity, :description,
|
56
56
|
:tags, :menus, :images, :maintainers, :awards, :opening_hours,
|
57
57
|
:holidays,
|
58
|
-
|
58
|
+
|
59
59
|
### Utility:
|
60
60
|
:counters, :created_at, :updated_at, :status
|
61
|
-
|
61
|
+
|
62
62
|
lazy_load :tags, :menus, :maintainers, :opening_hours, :holidays
|
63
|
-
|
63
|
+
|
64
64
|
def geolocation=(new_coordinates)
|
65
65
|
@geolocation = Geolocation.parse(new_coordinates).tap do |geo|
|
66
66
|
attributes[:geolocation] = geo
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def menus=(new_menus)
|
71
71
|
@menus = new_menus.map do |attributes|
|
72
72
|
menu = Menu.new(attributes)
|
@@ -4,35 +4,35 @@ module Hungry
|
|
4
4
|
class Venue
|
5
5
|
class Collection < Hungry::Collection
|
6
6
|
include Pagination
|
7
|
-
|
7
|
+
|
8
8
|
def search(query)
|
9
9
|
all query: query
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def nearby(location, options = {})
|
13
13
|
options[:geolocation] = Geolocation.parse(location)
|
14
14
|
options[:sort_by] ||= 'distance'
|
15
|
-
|
15
|
+
|
16
16
|
all options
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def tagged_with(*tags)
|
20
20
|
all tags: (current_tags + tags.flatten).compact.join(',')
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def maintainable_by(user_or_id)
|
24
24
|
user_id = user_or_id.to_s =~ /^[0-9]+$/ ?
|
25
25
|
user_or_id.to_i : user_or_id.id
|
26
|
-
|
26
|
+
|
27
27
|
all maintainer_id: user_id
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def sort_by(subject)
|
31
31
|
all sort_by: subject
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
private
|
35
|
-
|
35
|
+
|
36
36
|
def current_tags
|
37
37
|
if criteria[:tags].is_a?(String)
|
38
38
|
criteria[:tags].gsub(/\s+/, '')
|
data/lib/support/presence.rb
CHANGED
@@ -2,118 +2,118 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Hungry::Geolocation do
|
4
4
|
let(:geo) { Hungry::Geolocation.new(50.8469397, 5.6927505) }
|
5
|
-
|
5
|
+
|
6
6
|
describe '.parse' do
|
7
7
|
context 'with a Geolocation' do
|
8
8
|
it 'returns the given Geolocation' do
|
9
9
|
expect(Hungry::Geolocation.parse(geo)).to eql geo
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
context 'with an Object' do
|
14
14
|
it 'returns a Geolocation object for objects with a latitude and longitude' do
|
15
15
|
object = Class.new do
|
16
16
|
def latitude; 50.8469397; end
|
17
17
|
def longitude; 5.6927505; end
|
18
18
|
end.new
|
19
|
-
|
19
|
+
|
20
20
|
geo = Hungry::Geolocation.parse(object)
|
21
21
|
expect(geo.latitude).to eql 50.8469397
|
22
22
|
expect(geo.longitude).to eql 5.6927505
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it 'returns a Geolocation object for objects with a lat and lng' do
|
26
26
|
object = Class.new do
|
27
27
|
def lat; 50.8469397; end
|
28
28
|
def lng; 5.6927505; end
|
29
29
|
end.new
|
30
|
-
|
30
|
+
|
31
31
|
geo = Hungry::Geolocation.parse(object)
|
32
32
|
expect(geo.latitude).to eql 50.8469397
|
33
33
|
expect(geo.longitude).to eql 5.6927505
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it 'returns a Geolocation object for objects that have a valid geolocation' do
|
37
37
|
object = Class.new do
|
38
38
|
def geolocation; Hungry::Geolocation.new(50.8469397, 5.6927505); end
|
39
39
|
end.new
|
40
|
-
|
40
|
+
|
41
41
|
geo = Hungry::Geolocation.parse(object)
|
42
42
|
expect(geo.latitude).to eql 50.8469397
|
43
43
|
expect(geo.longitude).to eql 5.6927505
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it 'returns nil for objects without geo information' do
|
47
47
|
geo = Hungry::Geolocation.parse(Object.new)
|
48
48
|
expect(geo).to be_nil
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it 'returns nil for objects that have an invalid geolocation' do
|
52
52
|
object = Class.new do
|
53
53
|
def geolocation; "just a string"; end
|
54
54
|
end.new
|
55
|
-
|
55
|
+
|
56
56
|
geo = Hungry::Geolocation.parse(object)
|
57
57
|
expect(geo).to be_nil
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
context 'with a String' do
|
62
62
|
it 'returns a Geolocation object' do
|
63
63
|
geo = Hungry::Geolocation.parse('50.8469397,5.6927505')
|
64
64
|
expect(geo.latitude).to eql 50.8469397
|
65
65
|
expect(geo.longitude).to eql 5.6927505
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it 'returns nil if the string can not be parsed' do
|
69
69
|
geo = Hungry::Geolocation.parse('not-a,geolocation')
|
70
70
|
expect(geo).to be_nil
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
context 'with an Array' do
|
75
75
|
it 'returns a Geolocation object' do
|
76
76
|
geo = Hungry::Geolocation.parse([50.8469397, 5.6927505])
|
77
77
|
expect(geo.latitude).to eql 50.8469397
|
78
78
|
expect(geo.longitude).to eql 5.6927505
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it 'returns nil if the array can not be parsed' do
|
82
82
|
geo = Hungry::Geolocation.parse(['not a', 'geolocation'])
|
83
83
|
expect(geo).to be_nil
|
84
84
|
end
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
context 'with a Hash' do
|
88
88
|
it 'returns a Geolocation object' do
|
89
89
|
geo = Hungry::Geolocation.parse(latitude: 50.8469397, longitude: 5.6927505)
|
90
90
|
expect(geo.latitude).to eql 50.8469397
|
91
91
|
expect(geo.longitude).to eql 5.6927505
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
it 'supports abbreviated keys' do
|
95
95
|
geo = Hungry::Geolocation.parse(lat: 50.8469397, lng: 5.6927505)
|
96
96
|
expect(geo.latitude).to eql 50.8469397
|
97
97
|
expect(geo.longitude).to eql 5.6927505
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
it 'returns nil if the hash can not be parsed' do
|
101
101
|
geo = Hungry::Geolocation.parse(a: 'b', c: 'd')
|
102
102
|
expect(geo).to be_nil
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
describe '#initialize' do
|
108
108
|
it 'sets latitude' do
|
109
109
|
expect(geo.latitude).to eql 50.8469397
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
it 'sets longitude' do
|
113
113
|
expect(geo.longitude).to eql 5.6927505
|
114
114
|
end
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
describe '#to_s' do
|
118
118
|
it 'joins latitude and longitude with a ","' do
|
119
119
|
expect(geo.to_s).to eql '50.8469397,5.6927505'
|
data/spec/hungry/util_spec.rb
CHANGED
@@ -7,44 +7,44 @@ describe Hungry::Util do
|
|
7
7
|
expect(hash).to include 'q' => 'ruby', 'lang' => 'en'
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
describe '#uri_with_params' do
|
12
12
|
it 'returns a clean URL if there no hash is given' do
|
13
13
|
url = Hungry::Util.uri_with_params('http://www.google.com/')
|
14
14
|
expect(url).to eql 'http://www.google.com/'
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it 'returns an URL with params representing the given hash' do
|
18
18
|
url = Hungry::Util.uri_with_params('http://www.google.com/search', 'q' => 'ruby', 'lang' => 'en')
|
19
19
|
expect(url).to eql 'http://www.google.com/search?q=ruby&lang=en'
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe '#is_numeric?' do
|
24
24
|
it 'returns true for integers' do
|
25
25
|
expect(Hungry::Util.is_numeric?(100)).to be true
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it 'returns true for floats' do
|
29
29
|
expect(Hungry::Util.is_numeric?(10.0)).to be true
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it 'returns true for integers in strings' do
|
33
33
|
expect(Hungry::Util.is_numeric?('100')).to be true
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it 'returns true for floats in strings' do
|
37
37
|
expect(Hungry::Util.is_numeric?('10.0')).to be true
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it 'returns true for negative integers in strings' do
|
41
41
|
expect(Hungry::Util.is_numeric?('-100')).to be true
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it 'returns true for negative floats in strings' do
|
45
45
|
expect(Hungry::Util.is_numeric?('-10.0')).to be true
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it 'returns false for non numeric values' do
|
49
49
|
expect(Hungry::Util.is_numeric?('abc')).to be false
|
50
50
|
expect(Hungry::Util.is_numeric?('1a3')).to be false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hungry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom-Eric Gerritsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -84,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
|
88
|
-
rubygems_version: 2.5.1
|
87
|
+
rubygems_version: 3.0.6
|
89
88
|
signing_key:
|
90
89
|
specification_version: 4
|
91
90
|
summary: An interface to the Eet.nu API.
|