wrapsquare 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/wrapsquare.rb +6 -0
- data/lib/wrapsquare/base.rb +34 -0
- data/lib/wrapsquare/place.rb +68 -0
- data/lib/wrapsquare/venues.rb +27 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OTYxMTdkMDYxMmQ4ZDVlNTFjMjlkNjFhODc5YTcwNGJhMmVlNjU4NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Y2U4NDUwN2Y1ZTVlMGFjMjYxYmQ4OTRiNmJjZDNhMmQ1ZTlhNjU4Ng==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NDgzNjc4OGFmZjVkMWJhNzkxMTA3NDY3ZDllOWEwYzMyMTQwMzM5YTQ2Mjcz
|
10
|
+
Zjc3ZGZhMTMyOTk2MjEyOGRmNzZlYzQwYjZmNzAxOTJiN2Y3ZDk3MmFlODdl
|
11
|
+
Yjg0ZmMwYmVkMWM1NDc2M2Y0ZWJiMzUwNzQ0OGEzYzI5MmUzN2I=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmRjNTcyNTYyMWY4YjZiZmRjNmQ4MTI4YjNkNjYwNzdiOWRiOWI2NTk0OGRl
|
14
|
+
OGJlNDU3MDFiZjRjOTI3MjYzNGQ3OWFiNDhkZTEyMWNkMDA1MDhjNTQ0OWRi
|
15
|
+
ZmRlMDFhYzI3ZDY4MTAyZDg0N2I2MTg4NTdiYjA2NmFmZDE0ZGE=
|
data/lib/wrapsquare.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Wrapsquare
|
2
|
+
class Base
|
3
|
+
|
4
|
+
API_URL = "https://api.foursquare.com/v2/venues/"
|
5
|
+
|
6
|
+
def initialize(args = {})
|
7
|
+
@oauth_token = args.fetch(:oauth_token, nil)
|
8
|
+
@version = args.fetch(:version, nil)
|
9
|
+
|
10
|
+
if @oauth_token.nil? || @oauth_token.nil?
|
11
|
+
raise ArgumentError, "You need to pass the oauth_token and the version"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def venues()
|
16
|
+
Wrapsquare::Venues.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(path, params={})
|
20
|
+
params = merge_set_up_params(params)
|
21
|
+
JSON.parse(Typhoeus::Request.get(API_URL + path, :params => params).body)["response"]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def merge_set_up_params(params)
|
27
|
+
if (!@oauth_token.nil? && !@version.nil?)
|
28
|
+
params.merge!(:oauth_token => @oauth_token)
|
29
|
+
params.merge(:v => @version)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Wrapsquare
|
2
|
+
|
3
|
+
class Place
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
def initialize(place)
|
7
|
+
@place = place
|
8
|
+
end
|
9
|
+
|
10
|
+
def id
|
11
|
+
@place["id"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def longitude
|
15
|
+
@place["location"]["lng"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def latitude
|
19
|
+
@place["location"]["lat"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
@place["name"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def postcode
|
27
|
+
@place["location"]["postalCode"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def city
|
31
|
+
@place["location"]["city"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def address
|
35
|
+
@place["location"]["address"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def country
|
39
|
+
@place["location"]["country"]
|
40
|
+
end
|
41
|
+
|
42
|
+
# return the icon url if exist or return the default icon
|
43
|
+
def icon
|
44
|
+
if (@place["categories"][0] != nil)
|
45
|
+
@place["categories"][0]["icon"]["prefix"] + "64" + @place["categories"][0]["icon"]["suffix"]
|
46
|
+
else
|
47
|
+
"https://ss1.4sqi.net/img/categories_v2/building/default_64.png"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Serialize object into json
|
52
|
+
def to_json(*a)
|
53
|
+
{
|
54
|
+
:id => self.id,
|
55
|
+
:longitude => self.longitude,
|
56
|
+
:latitude => self.latitude,
|
57
|
+
:name => self.name,
|
58
|
+
:postcode => self.postcode,
|
59
|
+
:city => self.city,
|
60
|
+
:address => self.address,
|
61
|
+
:country => self.country,
|
62
|
+
:icon => self.icon
|
63
|
+
}.to_json(*a)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Wrapsquare
|
2
|
+
|
3
|
+
class Venues
|
4
|
+
|
5
|
+
def initialize(foursquare)
|
6
|
+
@fq = foursquare
|
7
|
+
end
|
8
|
+
|
9
|
+
# find a specific venue
|
10
|
+
def find(id)
|
11
|
+
@venue = @fq.get("#{id}/?", {})["venue"]
|
12
|
+
return Wrapsquare::Place.new(@venue)
|
13
|
+
end
|
14
|
+
|
15
|
+
# search venues by latitude & longitude
|
16
|
+
def search(lat, lon, radius = 800, limit = 10)
|
17
|
+
@venues = @fq.get("search?", {:ll => "#{lat},#{lon}", :intent => "browse", :limit => limit, :radius => radius})
|
18
|
+
# map the venues into objets
|
19
|
+
@places = []
|
20
|
+
@places += @venues["venues"].map do |item|
|
21
|
+
Wrapsquare::Place.new(item)
|
22
|
+
end
|
23
|
+
return @places
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wrapsquare
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mourad Sabour
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: An ORM (Object Relational Mapper) that maps Foursquare API venues to
|
14
|
+
Ruby objects.
|
15
|
+
email: mourad.sabour@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/wrapsquare.rb
|
21
|
+
- lib/wrapsquare/base.rb
|
22
|
+
- lib/wrapsquare/place.rb
|
23
|
+
- lib/wrapsquare/venues.rb
|
24
|
+
homepage: http://rubygems.org/gems/wrapsquare
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.0.3
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Foursquare API gem
|
48
|
+
test_files: []
|