nom-ruby 0.2.0
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.
- data/CHANGELOG.md +12 -0
- data/CONTRIBUTORS.md +1 -0
- data/Gemfile +4 -0
- data/LICENSE.md +19 -0
- data/README.md +100 -0
- data/lib/nom-ruby/api.rb +68 -0
- data/lib/nom-ruby/fetcher.rb +55 -0
- data/lib/nom-ruby/keys.rb +11 -0
- data/lib/nom-ruby/util.rb +10 -0
- data/lib/nom-ruby/version.rb +9 -0
- data/lib/nom-ruby.rb +11 -0
- data/nom-ruby.gemspec +30 -0
- data/spec/location_spec.rb +0 -0
- data/spec/user_spec.rb +0 -0
- data/spec/util_spec.rb +0 -0
- metadata +153 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
###Changelog for nom-ruby
|
2
|
+
|
3
|
+
####0.1.{ 0 - 20 } - Initial Dev Release
|
4
|
+
- Author: Brian Norton
|
5
|
+
- Support for basic Location Fetching, and User Management
|
6
|
+
|
7
|
+
####0.2.0 - Initial Public Release
|
8
|
+
- Author: Brian Norton
|
9
|
+
- Locations { here, search}
|
10
|
+
- Users { register, login, search }
|
11
|
+
- Seen at [rubygems/nom-ruby]() and [github/nom-ruby](https://github.com/bnorton/nom-ruby)
|
12
|
+
|
data/CONTRIBUTORS.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Brian Norton - [github (@bnorton)](http://github.com/bnorton) - [twitter (@nort)](http://twitter.com/nort)
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Nom [justnom.it](http://justnom.it)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to
|
8
|
+
do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# nom-ruby
|
2
|
+
- The bindings for the Nom API in ruby
|
3
|
+
|
4
|
+
### Examples of the headless API
|
5
|
+
- https://justnom.it/locations/here.json?lat=37.7969398498535&lng=-122.399559020996
|
6
|
+
- https://justnom.it/activities.json?user_nid=4eccc0fbeef0a64dcf000001
|
7
|
+
- https://justnom.it/locations/search.json?lng=-122.3898&lat=37.81273&query=king
|
8
|
+
|
9
|
+
## Usage:
|
10
|
+
@api_handle = Nom::API.new(:key => "your developer key")
|
11
|
+
@user = @api_handle.login('user_name or email', 'password')
|
12
|
+
@locations = @api_handle.here(:lat => 33.3, :lng => -122.2)
|
13
|
+
@activities = @api_handle.activities(:user_nid => '4eccc0fbeef0a64dcf000001')
|
14
|
+
@api_handle.recommend(:text => 'I Just Nommed at ...', :user_nid => '4eccc0fbeef0a64dcf000001', :auth_token => '2af...fad3y')
|
15
|
+
@api_handle.thumb(:location_nid => "4edgc0fbadf0a64dcf110037", :user_nid => '4eccc0fbeef0a64dcf000001', :auth_token => '2af...fad3y')
|
16
|
+
|
17
|
+
## All Success Results Take the Form:
|
18
|
+
{
|
19
|
+
"status": 1,
|
20
|
+
"message": "OK",
|
21
|
+
"results": [
|
22
|
+
{"result": 1},
|
23
|
+
{"result": 2},
|
24
|
+
...,
|
25
|
+
{"result": "n"}
|
26
|
+
]
|
27
|
+
}
|
28
|
+
|
29
|
+
## All Error Results Take the Form:
|
30
|
+
{
|
31
|
+
"status": -1,
|
32
|
+
"message": "Some display-ready message about what the error was",
|
33
|
+
"results": []
|
34
|
+
}
|
35
|
+
|
36
|
+
## User:
|
37
|
+
{
|
38
|
+
name: "Brian Norton",
|
39
|
+
city: "San Francisco",
|
40
|
+
created_at: "2011-11-23T09:46:35Z",
|
41
|
+
image_url: "https://graph.facebook.com/679816146/picture?type=large",
|
42
|
+
updated_at: "2011-12-20T07:06:57Z",
|
43
|
+
url: "http://justnom.it/users/bn",
|
44
|
+
has_joined: true,
|
45
|
+
follower_count: 16,
|
46
|
+
user_nid: "4eccc0fbeef0a64dcf000001",
|
47
|
+
screen_name: "bn"
|
48
|
+
}
|
49
|
+
|
50
|
+
## Location:
|
51
|
+
{
|
52
|
+
name: "The Grove Cafe Yerba Buena",
|
53
|
+
location_nid: "4ec8b964eef0a679f80005be",
|
54
|
+
primary_category: "4ec8b8a7eef0a679f8000001",
|
55
|
+
secondary_category: "4ec8b8cdeef0a679f8000151",
|
56
|
+
cross_street: "Between 3rd St and Annie St",
|
57
|
+
address: "690 Mission St San Francisco, CA 94105-4014",
|
58
|
+
street: "690 Mission St",
|
59
|
+
city: "San Francisco",
|
60
|
+
state: "California"
|
61
|
+
woeid: "12797156",
|
62
|
+
rank_value: 38,
|
63
|
+
gowalla_url: null,
|
64
|
+
fsq_id: "4b7ef75cf964a520ee0c30e3",
|
65
|
+
created_at: "2011-11-20T08:25:08Z",
|
66
|
+
cost: "$$",
|
67
|
+
updated_at: "2011-12-08T17:13:23Z",
|
68
|
+
url: null,
|
69
|
+
timeofday: "lunch | dinner",
|
70
|
+
rank: "38/7821",
|
71
|
+
phone: "415-957-0558",
|
72
|
+
neighborhoods: "Financial District South",
|
73
|
+
yid: "45199920"
|
74
|
+
}
|
75
|
+
|
76
|
+
## Recommendation:
|
77
|
+
{
|
78
|
+
created_at: "2011-12-21T07:21:19Z",
|
79
|
+
location: @location,
|
80
|
+
title: null,
|
81
|
+
token: "7LVSG",
|
82
|
+
recommendation_nid: "4ef188efeef0a603e3000002",
|
83
|
+
text: "I just Nommed @ Velvet Room justnom.it/r/7LVSG",
|
84
|
+
user: @user,
|
85
|
+
image: {
|
86
|
+
size: "600x320#",
|
87
|
+
url: "http://static.justnom.it/8e637e6585609c9df21577afc2b333dabeeb32c6.medium.png",
|
88
|
+
image_nid: "4ee56d6beef0a61a7d000003"
|
89
|
+
},
|
90
|
+
lng: -122.41,
|
91
|
+
lat: 37.7892
|
92
|
+
}
|
93
|
+
|
94
|
+
## Thumb
|
95
|
+
{
|
96
|
+
user_nid: "4eccc137eef0a64dcf000002",
|
97
|
+
created_at: "2011-12-21T05:03:22Z",
|
98
|
+
location: @location,
|
99
|
+
value: 1
|
100
|
+
}
|
data/lib/nom-ruby/api.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Nom
|
2
|
+
class API
|
3
|
+
|
4
|
+
def here(lat, lng, options = {})
|
5
|
+
start, limit = Nom::Util.page(options)
|
6
|
+
Nom::API.handle.get('/locations/here', {
|
7
|
+
:lat => lat,
|
8
|
+
:lng => lng,
|
9
|
+
:dist => (options[:dist] || 0.5),
|
10
|
+
:start => start,
|
11
|
+
:limit => limit
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
def location_search(query, options = {})
|
16
|
+
start, limit = Nom::Util.page(options)
|
17
|
+
params = { :query => query }
|
18
|
+
|
19
|
+
params.merge!({
|
20
|
+
:lat => options[:lat],
|
21
|
+
:lng => options[:lng]
|
22
|
+
}) if(options[:lat].present? && options[:lng].present?)
|
23
|
+
|
24
|
+
params.merge!({
|
25
|
+
:location => options[:location]
|
26
|
+
}) if options[:location].present?
|
27
|
+
|
28
|
+
Nom::API.handle.get('/locations/search', params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def register(email, password, options ={})
|
32
|
+
Nom::API.handle.post('/users/register', {
|
33
|
+
:email => email,
|
34
|
+
:password => password,
|
35
|
+
:screen_name => options[:screen_name],
|
36
|
+
:name => options[:name],
|
37
|
+
:city => options[:city]
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
# Any item out of email, user_nid, screen_name will work
|
42
|
+
def login(password, options ={})
|
43
|
+
Nom::API.handle.post('/users/login', {
|
44
|
+
:password => password,
|
45
|
+
:email => options[:email],
|
46
|
+
:user_nid => options[:user_nid],
|
47
|
+
:screen_name => options[:screen_name]
|
48
|
+
})
|
49
|
+
end
|
50
|
+
|
51
|
+
def user_search(query, options = {})
|
52
|
+
start, limit = Nom::Util.page(options)
|
53
|
+
Nom::API.handle.get('/locations/search', {
|
54
|
+
:query => query, # If the input value is of unknown origin
|
55
|
+
:screen_name => options[:screen_name],
|
56
|
+
:email => options[:email]
|
57
|
+
})
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# keep this around for re-use
|
63
|
+
def self.handle
|
64
|
+
@handle ||= Nom::Fetcher.new # (:key => Nom::Keys.developer, :secret => Nom::Keys.secret)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Nom
|
2
|
+
class Fetcher
|
3
|
+
|
4
|
+
def post(path, body = {})
|
5
|
+
url = url_for_path(path)
|
6
|
+
go(url, Net::HTTP::Post, body)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(path, params = {})
|
10
|
+
url = url_for_path(path)
|
11
|
+
add_params(url, params)
|
12
|
+
go(url, Net::HTTP::Get)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def port
|
18
|
+
443
|
19
|
+
end
|
20
|
+
|
21
|
+
def base_url
|
22
|
+
"https://justnom.it"
|
23
|
+
end
|
24
|
+
|
25
|
+
def start(url)
|
26
|
+
uri = URI.parse(url)
|
27
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
28
|
+
http.use_ssl = true
|
29
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
30
|
+
[http, uri]
|
31
|
+
end
|
32
|
+
|
33
|
+
def go(url, type, body=nil)
|
34
|
+
http,uri = start(url)
|
35
|
+
request = type.new(uri.request_uri)
|
36
|
+
request.set_form_data(body) if(body.kind_of?(Hash) && body.present?)
|
37
|
+
JSON.parse(http.request(request).body) rescue {}
|
38
|
+
end
|
39
|
+
|
40
|
+
# always request json
|
41
|
+
def url_for_path(path)
|
42
|
+
url = "#{base_url}#{path}"
|
43
|
+
url << '.json' unless url =~ /\.json$/
|
44
|
+
end
|
45
|
+
|
46
|
+
# if any params are present
|
47
|
+
def add_params(url, params)
|
48
|
+
return unless params.kind_of? Hash
|
49
|
+
extra = (url =~ /\?/) ? "&" : "?"
|
50
|
+
url << extra
|
51
|
+
url << params.to_param unless params.blank?
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/lib/nom-ruby.rb
ADDED
data/nom-ruby.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/nom-ruby/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "nom-ruby"
|
6
|
+
s.version = GemNom::VERSION::STRING
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.author = 'Brian Norton'
|
9
|
+
s.email = ["team@justnom.it"]
|
10
|
+
s.homepage = "https://github.com/bnorton/nom-ruby"
|
11
|
+
s.summary = "Nom API ruby client"
|
12
|
+
s.description = "Ruby client for using the Nom API. Nom is the best way to find out what's best in your world."
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "nom-ruby"
|
16
|
+
|
17
|
+
s.add_dependency 'json', '>= 1.4.6'
|
18
|
+
|
19
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
20
|
+
s.add_development_dependency "gemcutter", ">= 0.6.1"
|
21
|
+
s.add_development_dependency "rspec", "~> 2.2"
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n") - ['.rvmrc', '.gitignore']
|
24
|
+
s.test_files = `git ls-files`.split("\n").grep(/^spec/)
|
25
|
+
s.require_paths = %w[lib]
|
26
|
+
|
27
|
+
s.extra_rdoc_files = ['README.md', 'LICENSE.md', 'CHANGELOG.md']
|
28
|
+
s.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'nom-ruby', '--main', 'README.md']
|
29
|
+
|
30
|
+
end
|
File without changes
|
data/spec/user_spec.rb
ADDED
File without changes
|
data/spec/util_spec.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nom-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brian Norton
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-12-30 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 11
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 4
|
32
|
+
- 6
|
33
|
+
version: 1.4.6
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 23
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
version: 1.0.0
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: gemcutter
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 5
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
- 6
|
64
|
+
- 1
|
65
|
+
version: 0.6.1
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rspec
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 7
|
77
|
+
segments:
|
78
|
+
- 2
|
79
|
+
- 2
|
80
|
+
version: "2.2"
|
81
|
+
type: :development
|
82
|
+
version_requirements: *id004
|
83
|
+
description: Ruby client for using the Nom API. Nom is the best way to find out what's best in your world.
|
84
|
+
email:
|
85
|
+
- team@justnom.it
|
86
|
+
executables: []
|
87
|
+
|
88
|
+
extensions: []
|
89
|
+
|
90
|
+
extra_rdoc_files:
|
91
|
+
- README.md
|
92
|
+
- LICENSE.md
|
93
|
+
- CHANGELOG.md
|
94
|
+
files:
|
95
|
+
- CHANGELOG.md
|
96
|
+
- CONTRIBUTORS.md
|
97
|
+
- Gemfile
|
98
|
+
- LICENSE.md
|
99
|
+
- README.md
|
100
|
+
- lib/nom-ruby.rb
|
101
|
+
- lib/nom-ruby/api.rb
|
102
|
+
- lib/nom-ruby/fetcher.rb
|
103
|
+
- lib/nom-ruby/keys.rb
|
104
|
+
- lib/nom-ruby/util.rb
|
105
|
+
- lib/nom-ruby/version.rb
|
106
|
+
- nom-ruby.gemspec
|
107
|
+
- spec/location_spec.rb
|
108
|
+
- spec/user_spec.rb
|
109
|
+
- spec/util_spec.rb
|
110
|
+
homepage: https://github.com/bnorton/nom-ruby
|
111
|
+
licenses: []
|
112
|
+
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options:
|
115
|
+
- --line-numbers
|
116
|
+
- --inline-source
|
117
|
+
- --title
|
118
|
+
- nom-ruby
|
119
|
+
- --main
|
120
|
+
- README.md
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: 23
|
138
|
+
segments:
|
139
|
+
- 1
|
140
|
+
- 3
|
141
|
+
- 6
|
142
|
+
version: 1.3.6
|
143
|
+
requirements: []
|
144
|
+
|
145
|
+
rubyforge_project: nom-ruby
|
146
|
+
rubygems_version: 1.8.11
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: Nom API ruby client
|
150
|
+
test_files:
|
151
|
+
- spec/location_spec.rb
|
152
|
+
- spec/user_spec.rb
|
153
|
+
- spec/util_spec.rb
|