dagjeweg 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/dagjeweg/engine.rb +1 -1
- data/lib/dagjeweg/tip.rb +35 -38
- data/lib/dagjeweg/version.rb +1 -1
- data/spec/tip_spec.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 007900558d35b96a46cd77cb23cb574312952c6e
|
4
|
+
data.tar.gz: edf7614d10a036f90ba0dc92cbbc67872be18e83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f8dc4aa290e1cace6153e6cd0095f0a4277f9145cdf4f28db86ab0a788cfe92037e313866276d1e7d8a3839f1f9f739e72edd4e460b731525da88d17b30d2bd
|
7
|
+
data.tar.gz: b286a44ae8e67c40bda9e8c7a01f49560e36b396db2f7db3deea051cc6d84c4de03f97fe8395393bec887efdfaa92810bd72f6c2da5bdd20b03ba8c6b463a0aa
|
data/README.md
CHANGED
@@ -20,6 +20,14 @@ Of installeer het zelf:
|
|
20
20
|
|
21
21
|
$ gem install dagjeweg
|
22
22
|
|
23
|
+
## Configuratie in Rails applicatie
|
24
|
+
Pas de configuratie van de environment aan (development.rb, production.rb, etc.)
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
config.dagjeweg.api_key = "voerhierjouwmd5apikeyin"
|
28
|
+
```
|
29
|
+
|
30
|
+
|
23
31
|
## Gebruik
|
24
32
|
|
25
33
|
Mogelijkheden:
|
@@ -82,7 +90,7 @@ De volgende velden kunnen worden opgevraagd van iedere tip:
|
|
82
90
|
@tips.first.nearby(5)
|
83
91
|
|
84
92
|
# Vraag reviews van een uitstapje op
|
85
|
-
@reviews =
|
93
|
+
@reviews = Dagjeweg::Tip.find(22).reviews
|
86
94
|
```
|
87
95
|
|
88
96
|
## API Key
|
data/lib/dagjeweg/engine.rb
CHANGED
data/lib/dagjeweg/tip.rb
CHANGED
@@ -13,23 +13,20 @@ module Dagjeweg
|
|
13
13
|
args.each do |k,v|
|
14
14
|
instance_variable_set("@#{k}", v) unless v.nil?
|
15
15
|
end
|
16
|
-
|
17
|
-
self.price = price.to_i unless price == ''
|
18
|
-
self.price_kids = price_kids.to_i unless price_kids == ''
|
19
|
-
self.price_toddlers = price_toddlers.to_i unless price_toddlers == ''
|
20
|
-
self.price_seniors = price_seniors.to_i unless price_seniors == ''
|
16
|
+
typecast_attrs
|
21
17
|
end
|
22
18
|
|
19
|
+
|
23
20
|
# returns a list of tips for given query
|
24
21
|
def self.search(query="", per_page=50, page=1)
|
25
|
-
|
26
|
-
unless
|
22
|
+
search_tips = []
|
23
|
+
unless search_tips.any?
|
27
24
|
uri = Dagjeweg::Tip.api_url("search.json?q=#{query}&per_page=#{per_page}&page=#{page}")
|
28
25
|
json = Dagjeweg::Tip.get_json(uri)
|
29
26
|
for object in json
|
30
|
-
|
27
|
+
search_tips << Dagjeweg::Tip.new(object)
|
31
28
|
end
|
32
|
-
return
|
29
|
+
return search_tips
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
@@ -51,38 +48,22 @@ module Dagjeweg
|
|
51
48
|
def self.near(lat, lon, per_page)
|
52
49
|
uri = Dagjeweg::Tip.api_url("tips.json?lat=#{lat}&lon=#{lon}&per_page=#{per_page}")
|
53
50
|
json = Dagjeweg::Tip.get_json(uri)
|
54
|
-
|
55
|
-
a = []
|
56
|
-
for object in json
|
57
|
-
a << Dagjeweg::Tip.new(json.first)
|
58
|
-
end
|
59
|
-
return a
|
60
|
-
else
|
61
|
-
raise DagjewegError.new("Tip met deze ID werd niet gevonden.")
|
62
|
-
end
|
51
|
+
Dagjeweg::Tip.parse_json(json)
|
63
52
|
end
|
64
53
|
|
65
54
|
# returns a list of tips in the range of x kilometers of this instance
|
66
55
|
def nearby(range=10)
|
67
56
|
uri = Dagjeweg::Tip.api_url("nearby.json?id=#{id.to_s}")
|
68
57
|
json = Dagjeweg::Tip.get_json(uri)
|
69
|
-
|
70
|
-
a = []
|
71
|
-
for object in json
|
72
|
-
a << Dagjeweg::Tip.new(json.first)
|
73
|
-
end
|
74
|
-
return a
|
75
|
-
else
|
76
|
-
raise DagjewegError.new("Tip met deze ID werd niet gevonden.")
|
77
|
-
end
|
58
|
+
Dagjeweg::Tip.parse_json(json)
|
78
59
|
end
|
79
60
|
|
80
61
|
# returns a list of review objects
|
81
62
|
def reviews
|
82
|
-
|
83
|
-
unless
|
63
|
+
reviews = []
|
64
|
+
unless reviews.any?
|
84
65
|
for object in show_reviews
|
85
|
-
|
66
|
+
reviews << Dagjeweg::Review.new(
|
86
67
|
tip_id: id,
|
87
68
|
reviewer: object["reviewer"],
|
88
69
|
title: object["title"],
|
@@ -94,7 +75,7 @@ module Dagjeweg
|
|
94
75
|
)
|
95
76
|
end
|
96
77
|
end
|
97
|
-
return
|
78
|
+
return reviews
|
98
79
|
end
|
99
80
|
|
100
81
|
# returns the DagjeWeg ID
|
@@ -113,18 +94,26 @@ module Dagjeweg
|
|
113
94
|
|
114
95
|
private
|
115
96
|
|
97
|
+
# Transform the json object in an Array of Tip instances
|
98
|
+
def self.parse_json(json)
|
99
|
+
a = []
|
100
|
+
for object in json
|
101
|
+
a << Dagjeweg::Tip.new(json.first)
|
102
|
+
end
|
103
|
+
return a
|
104
|
+
end
|
105
|
+
|
106
|
+
# Get the JSON object and return proper errors in scenarios where response code != 200 OK
|
116
107
|
def self.get_json(uri)
|
117
108
|
resp = Net::HTTP.get_response(URI.parse(uri))
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
elsif resp.code.to_i == 404
|
109
|
+
case resp.code.to_i
|
110
|
+
when 200
|
111
|
+
return JSON.parse(resp.body)
|
112
|
+
when 404
|
123
113
|
raise DagjewegError.new(self), "Tip met deze ID werd niet gevonden. (#{resp.code})"
|
124
|
-
|
114
|
+
when 403
|
125
115
|
raise DagjewegError.new(self), "Ongeldige API Key (#{resp.code})"
|
126
116
|
else
|
127
|
-
puts resp
|
128
117
|
raise DagjewegError.new(self), "Onbekende fout (#{resp.code})"
|
129
118
|
end
|
130
119
|
end
|
@@ -137,5 +126,13 @@ module Dagjeweg
|
|
137
126
|
"http://m.dagjeweg.nl/api/#{Config.api_key}/"
|
138
127
|
end
|
139
128
|
|
129
|
+
def typecast_attrs
|
130
|
+
self.distance = distance.to_f unless distance == ''
|
131
|
+
self.price = price.to_i unless price == ''
|
132
|
+
self.price_kids = price_kids.to_i unless price_kids == ''
|
133
|
+
self.price_toddlers = price_toddlers.to_i unless price_toddlers == ''
|
134
|
+
self.price_seniors = price_seniors.to_i unless price_seniors == ''
|
135
|
+
end
|
136
|
+
|
140
137
|
end
|
141
138
|
end
|
data/lib/dagjeweg/version.rb
CHANGED
data/spec/tip_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dagjeweg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henk Meijer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|