simplegdata 0.0.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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/simplegdata/version.rb +3 -0
- data/lib/simplegdata.rb +93 -0
- data/simplegdata.gemspec +23 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/simplegdata.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require "simplegdata/version"
|
2
|
+
|
3
|
+
module SimpleGData
|
4
|
+
# A simple class that makes a oauth request using the oauth gem
|
5
|
+
# Initialize it by passing in a required oauth token and oauth
|
6
|
+
# secret recieved form an external service such as omniauth or
|
7
|
+
# the oauth gem.
|
8
|
+
class Request
|
9
|
+
def initialize(oauth_token, oauth_secret, params = {
|
10
|
+
:application_id => 'anonymous',
|
11
|
+
:application_secret => 'anonymous',
|
12
|
+
:site => 'https://www.google.com'
|
13
|
+
})
|
14
|
+
# Sets up the class variables. Defaults to Google's anonymous
|
15
|
+
# usage if no account is given.
|
16
|
+
@oauth_token = oauth_token
|
17
|
+
@oauth_secret = oauth_secret
|
18
|
+
@application_id = params[:application_id]
|
19
|
+
@application_secret = params[:application_secret]
|
20
|
+
@site = params[:site]
|
21
|
+
end
|
22
|
+
|
23
|
+
# A class method to make an optimized request to GData's APIS.
|
24
|
+
# Automatically converts the request to JSON and accepts a
|
25
|
+
# a ruby hash to convert to JSON to send for post data. Returns
|
26
|
+
# results back as a ruby array.
|
27
|
+
def request(rest, url, data = nil, options = nil)
|
28
|
+
# Default get requests to json
|
29
|
+
if rest == :get
|
30
|
+
unless url.include? 'alt=json'
|
31
|
+
if url.include? '?'
|
32
|
+
url = url + '&alt=json'
|
33
|
+
else
|
34
|
+
url = url + '?alt=json'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Default post requests to json
|
40
|
+
if options.nil?
|
41
|
+
options = { 'Content-Type' => 'application/json' }
|
42
|
+
else
|
43
|
+
unless options.has_key? 'Content-Type'
|
44
|
+
options['Content-Type'] = 'application/json'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Convert any data passed in for post requests to JSON
|
49
|
+
if data.class == {}.class
|
50
|
+
data = ActiveSupport::JSON.encode(data)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Run the query and return the results as a ruby object
|
54
|
+
response = request_raw(rest, url, data, options)
|
55
|
+
ActiveSupport::JSON.decode response
|
56
|
+
end
|
57
|
+
|
58
|
+
# A class method to process a raw request. All handling is
|
59
|
+
# done by the user. Deals with the unique issue of GData
|
60
|
+
# API's sometimes returning 302 redirects with gsessionids
|
61
|
+
# appended to them.
|
62
|
+
def request_raw(rest, url, data = nil, options = nil)
|
63
|
+
response = access_token.request(rest, url, data, options)
|
64
|
+
#if(rest == :post)
|
65
|
+
# raise response.to_yaml
|
66
|
+
#end
|
67
|
+
case response
|
68
|
+
when Net::HTTPSuccess then response.body
|
69
|
+
when Net::HTTPRedirection then access_token.request(rest, response['location'], data, options).body
|
70
|
+
else
|
71
|
+
response.error!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# An internal storage of the access token used to make requests
|
78
|
+
def access_token
|
79
|
+
@access_token ||= create_access_token
|
80
|
+
end
|
81
|
+
|
82
|
+
# Creates an oauth token based off the provided credentials
|
83
|
+
def create_access_token
|
84
|
+
consumer = OAuth::Consumer.new @application_id,
|
85
|
+
@application_secret,
|
86
|
+
:site => @site
|
87
|
+
token_hash = { :oauth_token => @oauth_token,
|
88
|
+
:oauth_token_secret => @oauth_secret }
|
89
|
+
access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/simplegdata.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "simplegdata/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "simplegdata"
|
7
|
+
s.version = Simplegdata::VERSION
|
8
|
+
s.authors = ["Charlie Moseley"]
|
9
|
+
s.email = ["charlie@wearemonkey.com"]
|
10
|
+
s.homepage = "http://wearemonkey.com"
|
11
|
+
s.summary = %q{A gem to run simple queries against GData with just an oauth token and secret}
|
12
|
+
s.description = %q{SimpleGData provides a simple way to run queries against the GData API's by providing just an oauth token and secret (assuming proper permissions are set) retrieved from a service such as omniauth or the oauth gem.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "simplegdata"
|
15
|
+
|
16
|
+
s.add_dependency('activesupport')
|
17
|
+
s.add_dependency('oauth')
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplegdata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Charlie Moseley
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-30 00:00:00.000000000 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
requirement: &2153418720 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2153418720
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: oauth
|
28
|
+
requirement: &2153418300 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2153418300
|
37
|
+
description: SimpleGData provides a simple way to run queries against the GData API's
|
38
|
+
by providing just an oauth token and secret (assuming proper permissions are set)
|
39
|
+
retrieved from a service such as omniauth or the oauth gem.
|
40
|
+
email:
|
41
|
+
- charlie@wearemonkey.com
|
42
|
+
executables: []
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- Rakefile
|
49
|
+
- lib/simplegdata.rb
|
50
|
+
- lib/simplegdata/version.rb
|
51
|
+
- simplegdata.gemspec
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://wearemonkey.com
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project: simplegdata
|
73
|
+
rubygems_version: 1.6.2
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: A gem to run simple queries against GData with just an oauth token and secret
|
77
|
+
test_files: []
|