trove_oauth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +39 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/trove_oauth.rb +26 -0
- data/lib/trove_oauth/account.rb +11 -0
- data/lib/trove_oauth/client.rb +90 -0
- data/lib/trove_oauth/photo.rb +37 -0
- data/lib/trove_oauth/photos.rb +23 -0
- data/lib/trove_oauth/plaintext.rb +9 -0
- data/lib/trove_oauth/services.rb +15 -0
- data/test/client_test.rb +50 -0
- data/test/test_helper.rb +11 -0
- metadata +122 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@trove
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
gem "oauth", "~> 0.4.5"
|
3
|
+
|
4
|
+
# Add dependencies to develop your gem here.
|
5
|
+
# Include everything needed to run rake, tests, features, etc.
|
6
|
+
group :development do
|
7
|
+
gem "shoulda", ">= 0"
|
8
|
+
gem "bundler", "~> 1.0.0"
|
9
|
+
gem "jeweler", "~> 1.6.4"
|
10
|
+
gem "rcov", ">= 0"
|
11
|
+
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Emma Persky
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
= trove_oauth (TroveOAuth)
|
2
|
+
|
3
|
+
A ruby wrapper for Trove (http://www.yourtrove.com), inspired by TwitterOAuth (http://github.com/moomerman/twitter_oauth)
|
4
|
+
|
5
|
+
Gem coming soon...
|
6
|
+
|
7
|
+
== Example Usage:
|
8
|
+
|
9
|
+
client = TroveOAuth::Client.new(:consumer_key => ..., :consumer_secret => ...)
|
10
|
+
request_token = @client.request_token(:oauth_callback => my_awesome_callback_url)
|
11
|
+
redirect_to request_token request_token.authorize_url
|
12
|
+
|
13
|
+
== meanwhile...
|
14
|
+
|
15
|
+
at your callback end point
|
16
|
+
|
17
|
+
access_token = client.authorize(request_token.token, request_token.secret, :oauth_verifier => verifier_recieved_at_callback)
|
18
|
+
|
19
|
+
== then you can do groovy things like:
|
20
|
+
|
21
|
+
client.info => {"first_name"=>"Emma", "last_name"=>"Persky", "trove_internal_id"=>"123456", "trove_email"=>"emma.persky@gmail.com", "trove_username"=>"emmapersky", "identities"=>{"photos"=>[["Flickr", "Emma Persky", "12345", 377], ["Facebook", "Emma Persky", "12345", 321]]}}
|
22
|
+
|
23
|
+
client.services => []
|
24
|
+
|
25
|
+
client.service('facebook') => []
|
26
|
+
|
27
|
+
client.service_bounceback_url('facebook', 'http://myawesomeserver.com/some_endpoint') => "https://www.yourtrove.com/some_magic_url_for_bounceback"
|
28
|
+
|
29
|
+
client.photos => {big ol' data structure for photos...}
|
30
|
+
client.photos(some params) => {smaller data structure of photos}
|
31
|
+
== in theory:
|
32
|
+
|
33
|
+
client.add_photo
|
34
|
+
client.add_photos
|
35
|
+
|
36
|
+
== Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2011 Emma Persky. See LICENSE.txt for
|
39
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "trove_oauth"
|
18
|
+
gem.homepage = "http://github.com/emmapersky/trove_oauth"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A Ruby wrapper for the Trove API}
|
21
|
+
gem.description = %Q{A Ruby wrapper for the Trove API - inspired by twitter_oauth}
|
22
|
+
gem.email = "emma.persky@gmail.com"
|
23
|
+
gem.authors = ["Emma Persky"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "trove_oauth #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/trove_oauth.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
require 'json'
|
3
|
+
#require 'mime/types'
|
4
|
+
require 'oauth'
|
5
|
+
require 'oauth/signature/plaintext'
|
6
|
+
|
7
|
+
require 'trove_oauth/client'
|
8
|
+
require 'trove_oauth/plaintext'
|
9
|
+
require 'trove_oauth/account'
|
10
|
+
require 'trove_oauth/photos'
|
11
|
+
require 'trove_oauth/services'
|
12
|
+
require 'trove_oauth/photo'
|
13
|
+
module TroveOAuth
|
14
|
+
VERSION = '0.0.1'
|
15
|
+
API_VERSION_PATH = "/v1"
|
16
|
+
SITE = 'https://www.yourtrove.com'
|
17
|
+
API = 'https://api.yourtrove.com'
|
18
|
+
|
19
|
+
class APIError < Exception
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class InternalError < Exception
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module TroveOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
@consumer_key = options[:consumer_key]
|
6
|
+
@consumer_secret = options[:consumer_secret]
|
7
|
+
@token = options[:token]
|
8
|
+
@secret = options[:secret]
|
9
|
+
@proxy = options[:proxy]
|
10
|
+
end
|
11
|
+
|
12
|
+
def authorize(token, secret, options = {})
|
13
|
+
request_token = OAuth::RequestToken.new(
|
14
|
+
consumer, token, secret
|
15
|
+
)
|
16
|
+
@access_token = request_token.get_access_token(options)
|
17
|
+
@token = @access_token.token
|
18
|
+
@secret = @access_token.secret
|
19
|
+
@access_token
|
20
|
+
end
|
21
|
+
|
22
|
+
def show(username)
|
23
|
+
get("/users/show/#{username}.json")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the string "ok" in the requested format with a 200 OK HTTP status code.
|
27
|
+
def test
|
28
|
+
get("/help/test.json")
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_token(options={})
|
32
|
+
consumer.get_request_token(options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def authentication_request_token(options={})
|
36
|
+
consumer.options[:authorize_path] = '/oauth/authenticate'
|
37
|
+
request_token(options)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
def access_token
|
43
|
+
@access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
|
49
|
+
def consumer
|
50
|
+
@consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret,
|
51
|
+
:site => API,
|
52
|
+
:authorize_path => '/oauth/authorize/',
|
53
|
+
:access_token_path => SITE + '/oauth/access_token/',
|
54
|
+
:request_token_path => '/oauth/request_token/',
|
55
|
+
:http_method => :get,
|
56
|
+
:signature_method => 'PLAINTEXT',
|
57
|
+
:scheme=> :query_string)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def get(path, headers={})
|
62
|
+
headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}")
|
63
|
+
oauth_response = access_token.get(path, headers)
|
64
|
+
JSON.parse(oauth_response.body)
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_without_json(path, headers={})
|
68
|
+
headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}")
|
69
|
+
oauth_response = access_token.get(path, headers)
|
70
|
+
oauth_response.body
|
71
|
+
end
|
72
|
+
|
73
|
+
def post(path, body='', headers={})
|
74
|
+
headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}")
|
75
|
+
oauth_response = access_token.post("/1#{path}", body, headers)
|
76
|
+
JSON.parse(oauth_response.body)
|
77
|
+
end
|
78
|
+
|
79
|
+
def post_without_json(path, body='', headers={})
|
80
|
+
headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}")
|
81
|
+
access_token.post("/1#{path}", body, headers).body
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete(path, headers={})
|
85
|
+
headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}")
|
86
|
+
oauth_response = access_token.delete("/1#{path}", headers)
|
87
|
+
JSON.parse(oauth_response.body)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module TroveOAuth
|
2
|
+
class Photo
|
3
|
+
attr_accessor :album_id, :date, :description, :height, :id, :license, :lat, :lng, :original_web_url, :owner, :photo_public, :service, :tags, :title, :urls, :width
|
4
|
+
|
5
|
+
def initialize(id, date, original_url)
|
6
|
+
self.id = id
|
7
|
+
self.date = date
|
8
|
+
self.urls = {:original => original_url}
|
9
|
+
self.tags = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_location(lat, lng)
|
13
|
+
self.lat = lat
|
14
|
+
self.lng = lng
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_json
|
18
|
+
{
|
19
|
+
'album_id' => album_id,
|
20
|
+
'date' => date.to_s,
|
21
|
+
'description' => description,
|
22
|
+
'height' => height,
|
23
|
+
'id' => id,
|
24
|
+
'license' => license,
|
25
|
+
'loc' => [lat, lng],
|
26
|
+
'original_web_url' => original_web_url,
|
27
|
+
'owner' => owner,
|
28
|
+
'public' => photo_public,
|
29
|
+
'service' => service,
|
30
|
+
'tags' => tags,
|
31
|
+
'title' => title,
|
32
|
+
'urls' => urls,
|
33
|
+
'width' => width
|
34
|
+
}.to_json
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TroveOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def add_photo(photo)
|
5
|
+
raise InternalError.new("Supplied photo must be of type TroveOAuth::Photo") unless photo.is_a? Photo
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def list_photos(params = {})
|
12
|
+
if params[:query_object]
|
13
|
+
|
14
|
+
else
|
15
|
+
params[:tags] = params[:tags].join(',') if params[:tags].is_a? Array
|
16
|
+
params[:services] = params[:services].join(',') if params[:services].is_a? Array
|
17
|
+
query_string = params.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
|
18
|
+
get("/v2/content/photos/?#{query_string}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TroveOAuth
|
2
|
+
class Client
|
3
|
+
def services
|
4
|
+
get("/v2/services/")
|
5
|
+
end
|
6
|
+
|
7
|
+
def service(service)
|
8
|
+
get("/v2/services/#{service}/")
|
9
|
+
end
|
10
|
+
|
11
|
+
def service_bounceback_url(service, redirect_url)
|
12
|
+
SITE + get_without_json("/v2/services/#{service}/bounceback")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/test/client_test.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/test_helper")
|
2
|
+
|
3
|
+
class ClientTest < Test::Unit::TestCase
|
4
|
+
include TroveOAuth
|
5
|
+
|
6
|
+
def test_
|
7
|
+
|
8
|
+
def test_some_test
|
9
|
+
false
|
10
|
+
puts "foo!"
|
11
|
+
raise 'x'
|
12
|
+
end
|
13
|
+
|
14
|
+
# context "A client instance" do
|
15
|
+
#
|
16
|
+
# setup do
|
17
|
+
# @client = Client.new
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# should "be kind of TroveOAuth" do
|
21
|
+
# assert_kind_of TroveOAuth::Client, @client
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# context "authentication_request_token" do
|
25
|
+
# setup do
|
26
|
+
# @consumer = stub("oauth consumer", :options => {})
|
27
|
+
# @client.stubs(:request_token)
|
28
|
+
# @client.stubs(:consumer).returns(@consumer)
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# should "sets consumers authorize path" do
|
32
|
+
# @client.authentication_request_token
|
33
|
+
# assert_equal @client.consumer.options[:authorize_path], '/oauth/authenticate'
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# context "when authorizing" do
|
38
|
+
# setup do
|
39
|
+
# @request_token = stub('a request token')
|
40
|
+
# @access_token = stub_everything('access token')
|
41
|
+
# @request_token.stubs(:get_access_token).returns(@access_token)
|
42
|
+
# OAuth::RequestToken.stubs(:new).returns(@request_token)
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# should "return an access token" do
|
46
|
+
# assert_equal @client.authorize("haha","haha"), @access_token
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
|
50
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trove_oauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Emma Persky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-12 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: oauth
|
17
|
+
requirement: &2152367780 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.4.5
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2152367780
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: shoulda
|
28
|
+
requirement: &2152366660 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2152366660
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
requirement: &2152365040 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.0.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2152365040
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jeweler
|
50
|
+
requirement: &2152364000 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.6.4
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2152364000
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rcov
|
61
|
+
requirement: &2152363020 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2152363020
|
70
|
+
description: A Ruby wrapper for the Trove API - inspired by twitter_oauth
|
71
|
+
email: emma.persky@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE.txt
|
76
|
+
- README.rdoc
|
77
|
+
files:
|
78
|
+
- .rvmrc
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.rdoc
|
82
|
+
- Rakefile
|
83
|
+
- VERSION
|
84
|
+
- lib/trove_oauth.rb
|
85
|
+
- lib/trove_oauth/account.rb
|
86
|
+
- lib/trove_oauth/client.rb
|
87
|
+
- lib/trove_oauth/photo.rb
|
88
|
+
- lib/trove_oauth/photos.rb
|
89
|
+
- lib/trove_oauth/plaintext.rb
|
90
|
+
- lib/trove_oauth/services.rb
|
91
|
+
- test/client_test.rb
|
92
|
+
- test/test_helper.rb
|
93
|
+
has_rdoc: true
|
94
|
+
homepage: http://github.com/emmapersky/trove_oauth
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: 1422787131755718388
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.6.2
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: A Ruby wrapper for the Trove API
|
122
|
+
test_files: []
|