hungry 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e23ebde7da2f1760c6504256a9520966ddb5b7cc6a1494bbe4764f590d0c4e28
|
4
|
+
data.tar.gz: e0ba51bf6aa0ca1e3e678c5d47030c95742e9fbcedfea677a1ef565729d430a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0c46d06c571ab606b5a158dca21795cde6b858dad5c6847465977ae102b93f7fe232d8cd6227f2991c98d4233920fb6a2fddf08545b827a474bdac9e9c48001
|
7
|
+
data.tar.gz: 9339bd32031272b9dcebad2d604071007005b6202f960ba7f17c5801aa8460b721bdf803e4d11762a31841d9619b05a35e1201dd25c928a8e9dc66e679432912
|
data/.travis.yml
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# SSH Key to pull private repositories:
|
2
|
-
source_key: "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb3dJQkFBS0NBUUVBM0MySG13YUFIOTQrOW9pb1NSU2I4enk3OHlQemxuL0hxcEdEVjhWREllR1NseTFPCi9VUmVpRnpkcEY2eEN1Y3RRWFkvVHA3QTBxKzMrMWd5cnBuZW00SWNVYUZTZ1kxelYxZ2JQY0VWVzJlWDIxVlEKN1pDdVBIYzFkbDI1K2gvbzQ3Z0l6aWwrT3dyUTNvdFVjdE9KNzk1ckxYZlp3SVAxMDZGcU9UTEhiWVluRGJjZgptYnZzSlllQmJtcEs3YlZndGs1cTdSUW5qWHlzRE0rWndObTZmamlOZWh5QTFCdlZrVWlpM2VQN3N1Q0g0ZHVUCkNVa3hKcFg2S3RKMzRxcHhvMDhlSDBvUUdSRDkrSEZjcDdYTEdJQmhCSzZhMzJTUURJci9KRy9CSWZnSTBYVkcKL1BsbU1wUmZpdlZkaGNXQUVNQmgzVzA4VkFLbmVpTUFXVUZYMFFJREFRQUJBb0lCQUJwVzJBSVRwUUFxOWgxSAorOW5DUFdXN3ZrQTM3TXYwUFU2S1djd0dMU0hBZW1qYllyZXBsaVY1OW9uVFNocWp6U1lubnlzb2txaWhuTURVCnJEdDI3TXB0cGpXZHR1RUlxdU9vQnBvOG52RndVeHBKK29SdzZtY1JXN1B0UW5KSm52S2U4VzY0U0FHSUtiUjEKdG9TR0NkcElJVW92TEQxN2k4emxZbSsxUTJZMmpXVVRoQ1VUMDh3WE1GWlZqd3BZaWdWeGNxYXQ1NWtNcUw0RwpRZGJXam1Ldm9UMkZMbDVWVCtqOERuRStlbEFhL2plamJVbURVNkRFVVZpYzdMNTM5ZG1ZNjBZVzhxSnkvajNUCkJlbHREK252RUhQTmZEY01UMkoxQks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MCtwRE5PZE5lOE4va3RLR25XSDI0bzJzTzNXWjkKMS84amtKR3MyNnhnUUg1TitQKzZXZXk4dDA5MFhyRHFFSHA1bEUyd0d4eGJSN3kwSTk5NUV2enYyU3d0c2ViUwo2STRLYXpVTTJMblJBbG5IOWdMWDhWaGJBZWIvN2xhQk9KODloQjROZGF2Y1gxZkRjcFd0Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg=="
|
3
|
-
|
4
1
|
# Project settings:
|
5
2
|
language: ruby
|
6
3
|
rvm:
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
data/hungry.gemspec
CHANGED
@@ -1,21 +1,18 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
3
|
-
require 'hungry'
|
4
|
-
|
5
2
|
Gem::Specification.new do |s|
|
6
3
|
s.name = 'hungry'
|
7
|
-
s.version =
|
4
|
+
s.version = '0.1.2'
|
8
5
|
s.authors = ['Tom-Eric Gerritsen']
|
9
6
|
s.email = ['tomeric@eet.nu']
|
10
7
|
s.homepage = 'http://github.com/eet-nu/hungry'
|
11
8
|
s.summary = %q{An interface to the Eet.nu API.}
|
12
9
|
s.description = %q{An interface to the Eet.nu API.}
|
13
|
-
|
10
|
+
|
14
11
|
s.files = `git ls-files`.split("\n")
|
15
12
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
13
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
14
|
s.require_paths = ['lib']
|
18
|
-
|
15
|
+
|
19
16
|
# specify any dependencies here:
|
20
17
|
s.add_dependency 'httparty'
|
21
18
|
end
|
data/lib/hungry.rb
CHANGED
@@ -1,33 +1,31 @@
|
|
1
1
|
$LOAD_PATH << File.expand_path('..', __FILE__)
|
2
|
-
|
2
|
+
|
3
3
|
require 'support/presence'
|
4
4
|
require 'support/symbolize_keys'
|
5
5
|
|
6
6
|
module Hungry
|
7
|
-
VERSION = '0.1.1'
|
8
|
-
|
9
7
|
class << self
|
10
8
|
attr_accessor :api_url, :credentials, :json_parser, :logger
|
11
9
|
end
|
12
|
-
|
10
|
+
|
13
11
|
def self.credentials=(new_credentials = {})
|
14
12
|
@credentials = new_credentials.symbolize_keys
|
15
|
-
|
13
|
+
|
16
14
|
Resource.basic_auth credentials[:username], credentials[:password]
|
17
15
|
Collection.basic_auth credentials[:username], credentials[:password]
|
18
16
|
end
|
19
|
-
|
17
|
+
|
20
18
|
### LIBRARY:
|
21
|
-
|
19
|
+
|
22
20
|
# Utility:
|
23
21
|
autoload :Collection, 'hungry/collection'
|
24
22
|
autoload :Resource, 'hungry/resource'
|
25
23
|
autoload :Util, 'hungry/util'
|
26
|
-
|
24
|
+
|
27
25
|
# Helpers:
|
28
26
|
autoload :Geolocation, 'hungry/geolocation'
|
29
27
|
autoload :Location, 'hungry/location'
|
30
|
-
|
28
|
+
|
31
29
|
# Models:
|
32
30
|
autoload :City, 'hungry/city'
|
33
31
|
autoload :Country, 'hungry/country'
|
@@ -39,17 +37,17 @@ module Hungry
|
|
39
37
|
autoload :Tag, 'hungry/tag'
|
40
38
|
autoload :User, 'hungry/user'
|
41
39
|
autoload :Venue, 'hungry/venue'
|
42
|
-
|
40
|
+
|
43
41
|
### EXCEPTIONS:
|
44
|
-
|
42
|
+
|
45
43
|
# Exception raised when a geolocation is required, but it is not given:
|
46
44
|
class GeolocationNotGiven < StandardError; end
|
47
|
-
|
45
|
+
|
48
46
|
# Exception raised when an endpoint is not specified for a resource:
|
49
47
|
class EndpointNotSpecified < StandardError; end
|
50
|
-
|
48
|
+
|
51
49
|
### CONFIGURATION:
|
52
|
-
|
50
|
+
|
53
51
|
self.credentials = { username: nil, password: nil }
|
54
52
|
self.api_url = 'https://api.eet.nu/'
|
55
53
|
self.json_parser = lambda do |json|
|
data/lib/hungry/city.rb
CHANGED
data/lib/hungry/collection.rb
CHANGED
@@ -4,42 +4,42 @@ module Hungry
|
|
4
4
|
class Collection
|
5
5
|
include Enumerable
|
6
6
|
include HTTParty
|
7
|
-
|
7
|
+
|
8
8
|
autoload :Pagination, 'hungry/collection/pagination'
|
9
|
-
|
9
|
+
|
10
10
|
attr_reader :klass, :endpoint, :criteria
|
11
|
-
|
11
|
+
|
12
12
|
### CLASS METHODS:
|
13
|
-
|
13
|
+
|
14
14
|
def self.get(*args)
|
15
15
|
self.base_uri Hungry.api_url
|
16
|
-
|
16
|
+
|
17
17
|
super
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
### INSTANCE METHODS:
|
21
|
-
|
21
|
+
|
22
22
|
def initialize(klass, endpoint, criteria = {})
|
23
23
|
@klass = klass
|
24
24
|
@endpoint = endpoint
|
25
25
|
@criteria = criteria.symbolize_keys
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def from_url(url)
|
29
29
|
uri = URI.parse(url)
|
30
30
|
options = Util.params_from_uri(uri) || klass.default_criteria
|
31
|
-
|
31
|
+
|
32
32
|
self.class.new(klass, uri.path, options)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def all(new_criteria = {})
|
36
36
|
self.class.new(klass, endpoint, criteria.merge(new_criteria))
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def [](index)
|
40
40
|
build_resource results[index]
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def first(n = 1)
|
44
44
|
if n == 1 && (value = results.first)
|
45
45
|
build_resource value
|
@@ -49,7 +49,7 @@ module Hungry
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def count(*args)
|
54
54
|
if args.present?
|
55
55
|
super
|
@@ -57,40 +57,40 @@ module Hungry
|
|
57
57
|
results.count
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def each(&block)
|
62
62
|
results.each do |result|
|
63
63
|
yield build_resource(result)
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def results
|
68
68
|
@results ||= json['results']
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def results=(results)
|
72
72
|
@results = results
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
protected
|
76
|
-
|
76
|
+
|
77
77
|
def build_resource(result)
|
78
78
|
resource = klass.new(result)
|
79
79
|
resource.data_source = data_source
|
80
80
|
resource
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def data_source
|
84
84
|
Util.uri_with_params(endpoint, criteria)
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
def json
|
88
88
|
@json ||= Util.parse_json(response.body)
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
def response
|
92
92
|
raise NoEndpointSpecified unless endpoint
|
93
|
-
|
93
|
+
|
94
94
|
@response ||= begin
|
95
95
|
Util.log "GET: #{data_source}"
|
96
96
|
self.class.get data_source
|
data/lib/hungry/country.rb
CHANGED
data/lib/hungry/geolocation.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
module Hungry
|
2
2
|
class Geolocation
|
3
3
|
attr_accessor :latitude, :longitude
|
4
|
-
|
4
|
+
|
5
5
|
def self.parse(input)
|
6
6
|
# input is already a Geolocation, so we can return it early:
|
7
7
|
return input if input.is_a?(self)
|
8
8
|
|
9
9
|
if input.respond_to?(:geolocation)
|
10
10
|
# input has a geolocation attribute, so try to use that one first:
|
11
|
-
geolocation = parse(input.geolocation)
|
11
|
+
geolocation = parse(input.geolocation)
|
12
12
|
return geolocation if geolocation
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
coordinates = []
|
16
|
-
|
16
|
+
|
17
17
|
if input.respond_to?(:latitude) && input.respond_to?(:longitude)
|
18
18
|
# input has latitude and longitude attributes, so use those:
|
19
19
|
coordinates = [input.latitude, input.longitude]
|
20
|
-
|
20
|
+
|
21
21
|
elsif input.respond_to?(:lat) && input.respond_to?(:lng)
|
22
22
|
# input has lat and lng attributes, so use those:
|
23
23
|
coordinates = [input.lat, input.lng]
|
24
|
-
|
24
|
+
|
25
25
|
elsif input.respond_to?(:match)
|
26
26
|
# Example: "50.8469397,5.6927505"
|
27
27
|
#
|
@@ -30,40 +30,40 @@ module Hungry
|
|
30
30
|
if match = input.match(/^([0-9\.]+),\s?([0-9\.]+)$/)
|
31
31
|
coordinates = [match[1], match[2]]
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
elsif input.respond_to?(:keys)
|
35
35
|
# Example: { latitude: 50.8469397, longitude: 5.6927505 }
|
36
36
|
#
|
37
37
|
# input is a Hash, so we can extract values with the keys:
|
38
38
|
coordinates = [input[:latitude] || input[:lat], input[:longitude] || input[:lng]]
|
39
|
-
|
39
|
+
|
40
40
|
elsif input.respond_to?(:[])
|
41
41
|
# Example: [50.8469397, 5.6927505]
|
42
42
|
#
|
43
43
|
# input is an Array, so we need the first and second value:
|
44
44
|
coordinates = input[0], input[1]
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
coordinates = coordinates.map(&:presence).compact
|
48
|
-
|
48
|
+
|
49
49
|
if coordinates.length == 2 && coordinates.all? { |coordinate| Util.is_numeric?(coordinate) }
|
50
50
|
new(*coordinates)
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def initialize(latitude, longitude)
|
55
55
|
self.latitude = latitude.to_f
|
56
56
|
self.longitude = longitude.to_f
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def to_s
|
60
60
|
[latitude, longitude].join(',')
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def [](key)
|
64
64
|
to_h.send(:[], key)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def []=(key, value)
|
68
68
|
case key.to_sym
|
69
69
|
when :latitude
|
@@ -72,7 +72,7 @@ module Hungry
|
|
72
72
|
self.longitude = value.to_f
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def to_h
|
77
77
|
{
|
78
78
|
latitude: latitude,
|
data/lib/hungry/location.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
module Hungry
|
2
2
|
class Location < Resource
|
3
|
-
|
3
|
+
|
4
4
|
self.endpoint = '/locations'
|
5
|
-
|
5
|
+
|
6
6
|
### RESOURCES:
|
7
|
-
|
7
|
+
|
8
8
|
has_many :venues, 'Hungry::Venue'
|
9
|
-
|
9
|
+
|
10
10
|
has_many :nearby_venues, 'Hungry::Venue'
|
11
|
-
|
11
|
+
|
12
12
|
has_many :tags, 'Hungry::Tag'
|
13
|
-
|
13
|
+
|
14
14
|
### ATTRIBUTES:
|
15
|
-
|
15
|
+
|
16
16
|
### Location:
|
17
17
|
attr_accessor :id, :name, :type, :url, :geolocation,
|
18
|
-
|
18
|
+
|
19
19
|
### Utility:
|
20
20
|
:resources, :counters
|
21
|
-
|
21
|
+
|
22
22
|
def geolocation=(new_coordinates)
|
23
23
|
@geolocation = Geolocation.parse(new_coordinates).tap do |geo|
|
24
24
|
attributes[:geolocation] = geo
|
data/lib/hungry/menu.rb
CHANGED
@@ -3,43 +3,43 @@ module Hungry
|
|
3
3
|
autoload :Category, 'hungry/menu/category'
|
4
4
|
autoload :Dish, 'hungry/menu/dish'
|
5
5
|
autoload :Option, 'hungry/menu/option'
|
6
|
-
|
6
|
+
|
7
7
|
self.endpoint = '/menus'
|
8
|
-
|
8
|
+
|
9
9
|
### RESOURCES:
|
10
|
-
|
10
|
+
|
11
11
|
belongs_to :venue, 'Hungry::Venue'
|
12
|
-
|
12
|
+
|
13
13
|
### ATTRIBUTES:
|
14
|
-
|
14
|
+
|
15
15
|
### Menu:
|
16
|
-
attr_accessor :id, :name, :type, :attachment,
|
17
|
-
|
16
|
+
attr_accessor :id, :name, :type, :attachment, :pages,
|
17
|
+
|
18
18
|
### Associations:
|
19
19
|
:categories, :venue,
|
20
|
-
|
20
|
+
|
21
21
|
### Utility:
|
22
22
|
:created_at, :updated_at
|
23
|
-
|
23
|
+
|
24
24
|
lazy_load :venue
|
25
|
-
|
25
|
+
|
26
26
|
def managed?
|
27
27
|
type == 'managed' || categories.present?
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def download?
|
31
31
|
type == 'download'
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def venue=(venue_attributes)
|
35
35
|
@venue = Hungry::Venue.new(venue_attributes)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def categories
|
39
39
|
@categories ||= []
|
40
40
|
end
|
41
41
|
lazy_load :categories
|
42
|
-
|
42
|
+
|
43
43
|
def categories=(new_categories)
|
44
44
|
@categories = new_categories.map do |attributes|
|
45
45
|
category = Menu::Category.new(attributes)
|
@@ -48,6 +48,6 @@ module Hungry
|
|
48
48
|
category
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
end
|
53
53
|
end
|