sayso-api-client 0.1.0 → 0.1.1
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/README.rdoc +4 -0
- data/lib/sayso.rb +27 -8
- data/sayso-api-client.gemspec +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
data/lib/sayso.rb
CHANGED
@@ -3,34 +3,47 @@ require 'crack'
|
|
3
3
|
require 'active_support/all'
|
4
4
|
#
|
5
5
|
# Example usage:
|
6
|
-
# sayso = Sayso.new(:consumer_key => 'your_key', :consumer_secret => 'your_secret')
|
6
|
+
# sayso = Sayso.new(:consumer_key => 'your_key', :consumer_secret => 'your_secret', :callback = 'http://localhost:3000')
|
7
7
|
# sayso.get("/places/search?what=restaurant&where=antwerpen")
|
8
8
|
# sayso.get("/places/search", :what => 'restaurant', :where => 'antwerpen')
|
9
9
|
# sayso.authorize_url # go here (=> "http://api.sayso.com/api1/oauth/authorize?oauth_token=some_token_hash")
|
10
10
|
# sayso.authorize_access_token('verifier')
|
11
|
+
# sayso.get_params # =>
|
11
12
|
# sayso.get("/users/current")
|
13
|
+
# sayso.get('/places/cj5C4oyiCr3Ra2aby-7U4a/reviews')
|
14
|
+
# review = '<?xml version="1.0" encoding="UTF-8"?><review><rating>2</rating><text>This is my review number 1. It is not so long but states that it works. We can see that everything is ok.</text></review>'
|
15
|
+
# sayso.post('/places/cj5C4oyiCr3Ra2aby-7U4a/reviews', review)
|
12
16
|
#
|
13
17
|
class Sayso
|
14
18
|
|
15
|
-
attr_accessor :version, :consumer_key, :consumer_secret, :base_url, :callback
|
19
|
+
attr_accessor :version, :consumer_key, :consumer_secret, :base_url, :callback, :get_params
|
16
20
|
attr_reader :access_token, :request_token, :response
|
17
21
|
|
22
|
+
# Example:
|
23
|
+
# Sayso.new(:consumer_key => 'your_key', :consumer_secret => 'your_secret', :language => 'nl-NL')
|
24
|
+
# The language parameter is optional.
|
18
25
|
def initialize(options = {})
|
19
26
|
options = {:version => 1, :base_url => 'http://api.sayso.com', :callback => nil}.merge(options)
|
27
|
+
|
28
|
+
# The language options is set to the get_params.
|
29
|
+
@get_params = {}
|
30
|
+
@get_params[:language] = options.delete(:language) if options[:language]
|
31
|
+
|
32
|
+
# All other options should be set to the related instance variable.
|
20
33
|
options.each do |attr, value|
|
21
34
|
instance_variable_set(:"@#{attr}", value)
|
22
35
|
end
|
23
36
|
self.initialize_access_token
|
24
37
|
end
|
25
38
|
|
26
|
-
def initialize_access_token
|
27
|
-
return @access_token
|
39
|
+
def initialize_access_token(force = false)
|
40
|
+
return @access_token if force || @access_token.nil?
|
28
41
|
@consumer = OAuth::Consumer.new(self.consumer_key, self.consumer_secret, {
|
29
42
|
:site => self.base_url,
|
30
43
|
:request_token_path => "/api#{self.version}/oauth/request_token",
|
31
44
|
:authorize_path => "/api#{self.version}/oauth/authorize",
|
32
45
|
:access_token_path => "/api#{self.version}/oauth/access_token" })
|
33
|
-
@request_token = @consumer.get_request_token(:oauth_callback =>
|
46
|
+
@request_token = @consumer.get_request_token(:oauth_callback => callback)
|
34
47
|
# Just make it using the request token (and a user that has given access ?!)
|
35
48
|
@access_token = OAuth::AccessToken.new(@consumer, @request_token.token, @request_token.secret)
|
36
49
|
end
|
@@ -53,6 +66,7 @@ class Sayso
|
|
53
66
|
# Access the unparsed response using the response method.
|
54
67
|
# Examples:
|
55
68
|
# get("/places/search?what=restaurant&where=antwerpen")
|
69
|
+
# get("/places/search", :what => 'restaurant', :where => 'antwerpen', :base_country => 'BE')
|
56
70
|
def get(path, params = {})
|
57
71
|
path = "/api#{self.version}#{path}"
|
58
72
|
path += "?#{params.to_query}" unless params.blank?
|
@@ -61,8 +75,13 @@ class Sayso
|
|
61
75
|
HashWithIndifferentAccess.new(result)
|
62
76
|
end
|
63
77
|
|
64
|
-
#
|
65
|
-
#
|
66
|
-
|
78
|
+
# Examples:
|
79
|
+
# post('/places/:place_id/reviews', :rating => 3, :text => "My review text that should be a certain length.")
|
80
|
+
def post(path, params = {})
|
81
|
+
path = "/api#{self.version}#{path}"
|
82
|
+
@response = @access_token.post(path, params, { 'Accept'=>'application/xml', 'Content-Type' => 'application/xml' })
|
83
|
+
result = Crack::XML.parse(@response.body)
|
84
|
+
HashWithIndifferentAccess.new(result)
|
85
|
+
end
|
67
86
|
|
68
87
|
end
|
data/sayso-api-client.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = %q{sayso-api-client}
|
5
|
-
spec.version = '0.1.
|
5
|
+
spec.version = '0.1.1'
|
6
6
|
spec.platform = Gem::Platform::RUBY
|
7
7
|
spec.description = spec.summary = 'Ruby gem to use the SaySo API (v1).'
|
8
8
|
spec.authors = ['Joost Hietbrink']
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sayso-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joost Hietbrink
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-25 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|