GooglePlus 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +56 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/GooglePlus.rb +26 -0
- data/lib/google_plus/api.rb +27 -0
- data/lib/google_plus/authenticatable.rb +25 -0
- data/lib/google_plus/base.rb +39 -0
- data/lib/google_plus/client.rb +29 -0
- data/lib/google_plus/client/activity.rb +10 -0
- data/lib/google_plus/client/comments.rb +10 -0
- data/lib/google_plus/client/users.rb +22 -0
- data/lib/google_plus/config.rb +103 -0
- data/lib/google_plus/configuration.rb +21 -0
- data/lib/google_plus/connection.rb +44 -0
- data/lib/google_plus/core_ext/hash.rb +66 -0
- data/lib/google_plus/creatable.rb +15 -0
- data/lib/google_plus/cursor.rb +45 -0
- data/lib/google_plus/direct_message.rb +28 -0
- data/lib/google_plus/error.rb +38 -0
- data/lib/google_plus/error/bad_gateway.rb +0 -0
- data/lib/google_plus/error/bad_request.rb +0 -0
- data/lib/google_plus/error/client_error.rb +8 -0
- data/lib/google_plus/error/enhance_your_calm.rb +0 -0
- data/lib/google_plus/error/forbidden.rb +8 -0
- data/lib/google_plus/error/internal_server_error.rb +0 -0
- data/lib/google_plus/error/not_acceptable.rb +0 -0
- data/lib/google_plus/error/not_found.rb +0 -0
- data/lib/google_plus/error/service_unavailable.rb +0 -0
- data/lib/google_plus/error/unauthorized.rb +8 -0
- data/lib/google_plus/geo_factory.rb +23 -0
- data/lib/google_plus/metadata.rb +8 -0
- data/lib/google_plus/request.rb +37 -0
- data/lib/google_plus/request/gateway.rb +21 -0
- data/lib/google_plus/request/multipart_with_file.rb +38 -0
- data/lib/google_plus/request/oauth.rb +27 -0
- data/lib/google_plus/request/phoenix.rb +23 -0
- data/lib/google_plus/response/parse_json.rb +24 -0
- data/lib/google_plus/response/raise_client_error.rb +54 -0
- data/lib/google_plus/response/raise_server_error.rb +30 -0
- data/lib/google_plus/size.rb +17 -0
- data/lib/google_plus/status.rb +87 -0
- data/lib/google_plus/user.rb +65 -0
- data/lib/google_plus/version.rb +31 -0
- data/test/helper.rb +19 -0
- data/test/test_GooglePlus.rb +14 -0
- metadata +255 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/core_ext/enumerable'
|
2
|
+
require 'google_plus/base'
|
3
|
+
require 'google_plus/size'
|
4
|
+
|
5
|
+
module GooglePlus
|
6
|
+
class Configuration < GooglePlus::Base
|
7
|
+
lazy_attr_reader :characters_reserved_per_media, :max_media_per_upload,
|
8
|
+
:non_username_paths, :photo_size_limit, :short_url_length, :short_url_length_https
|
9
|
+
|
10
|
+
# Returns an array of photo sizes
|
11
|
+
#
|
12
|
+
# @return [Array<GooglePlus::Size>]
|
13
|
+
def photo_sizes
|
14
|
+
@photo_sizes ||= Array(@attrs['photo_sizes']).each_with_object({}) do |(key, value), object|
|
15
|
+
object[key] = GooglePlus::Size.new(value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'google_plus/request/gateway'
|
3
|
+
require 'google_plus/request/multipart_with_file'
|
4
|
+
require 'google_plus/request/phoenix'
|
5
|
+
require 'google_plus/request/oauth'
|
6
|
+
require 'google_plus/response/parse_json'
|
7
|
+
require 'google_plus/response/raise_client_error'
|
8
|
+
require 'google_plus/response/raise_server_error'
|
9
|
+
|
10
|
+
module GooglePlus
|
11
|
+
module Connection
|
12
|
+
private
|
13
|
+
|
14
|
+
# Returns a Faraday::Connection object
|
15
|
+
#
|
16
|
+
# @return [Faraday::Connection]
|
17
|
+
def connection(options={})
|
18
|
+
merged_options = connection_options.merge({
|
19
|
+
:headers => {
|
20
|
+
:accept => 'application/json',
|
21
|
+
:user_agent => user_agent,
|
22
|
+
},
|
23
|
+
:proxy => proxy,
|
24
|
+
:ssl => {:verify => false},
|
25
|
+
:url => options.fetch(:endpoint, api_endpoint),
|
26
|
+
})
|
27
|
+
|
28
|
+
Faraday.new(merged_options) do |builder|
|
29
|
+
builder.use GooglePlus::Request::Phoenix if options[:phoenix]
|
30
|
+
builder.use GooglePlus::Request::MultipartWithFile
|
31
|
+
builder.use GooglePlus::Request::GooglePlusOAuth, credentials if credentials?
|
32
|
+
builder.use Faraday::Request::Multipart
|
33
|
+
builder.use Faraday::Request::UrlEncoded
|
34
|
+
builder.use GooglePlus::Request::Gateway, gateway if gateway
|
35
|
+
builder.use GooglePlus::Response::RaiseClientError
|
36
|
+
builder.use GooglePlus::Response::ParseJson unless options[:raw]
|
37
|
+
builder.use GooglePlus::Response::RaiseServerError
|
38
|
+
builder.adapter(adapter)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
# Take a single user ID or screen name and merge it into the hash with the correct key
|
4
|
+
#
|
5
|
+
# @param user_id_or_screen_name [Integer, String] A Twitter user ID or screen_name.
|
6
|
+
# @return [Hash]
|
7
|
+
def merge_user!(user_id_or_screen_name)
|
8
|
+
case user_id_or_screen_name
|
9
|
+
when Integer
|
10
|
+
self[:user_id] = user_id_or_screen_name
|
11
|
+
when String
|
12
|
+
self[:screen_name] = user_id_or_screen_name
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
# Take a multiple user IDs and screen names and merge them into the hash with the correct keys
|
18
|
+
#
|
19
|
+
# @param users_id_or_screen_names [Array] An array of Twitter user IDs or screen_names.
|
20
|
+
# @return [Hash]
|
21
|
+
def merge_users!(user_ids_or_screen_names)
|
22
|
+
user_ids, screen_names = [], []
|
23
|
+
user_ids_or_screen_names.flatten.each do |user_id_or_screen_name|
|
24
|
+
case user_id_or_screen_name
|
25
|
+
when Integer
|
26
|
+
user_ids << user_id_or_screen_name
|
27
|
+
when String
|
28
|
+
screen_names << user_id_or_screen_name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
self[:user_id] = user_ids.join(',') unless user_ids.empty?
|
32
|
+
self[:screen_name] = screen_names.join(',') unless screen_names.empty?
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
# Take a single owner ID or owner screen name and merge it into the hash with the correct key
|
37
|
+
# (for Twitter API endpoints that want :owner_id and :owner_screen_name)
|
38
|
+
#
|
39
|
+
# @param owner_id_or_owner_screen_name [Integer, String] A Twitter user ID or screen_name.
|
40
|
+
# @return [Hash]
|
41
|
+
def merge_owner!(owner_id_or_owner_screen_name)
|
42
|
+
case owner_id_or_owner_screen_name
|
43
|
+
when Integer
|
44
|
+
self[:owner_id] = owner_id_or_owner_screen_name
|
45
|
+
when String
|
46
|
+
self[:owner_screen_name] = owner_id_or_owner_screen_name
|
47
|
+
end
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# Take a single list ID or slug and merge it into the hash with the correct key
|
52
|
+
#
|
53
|
+
# @param list_id_or_slug [Integer, String] A Twitter list ID or slug.
|
54
|
+
# @return [Hash]
|
55
|
+
def merge_list!(list_id_or_screen_name)
|
56
|
+
case list_id_or_screen_name
|
57
|
+
when Integer
|
58
|
+
self[:list_id] = list_id_or_screen_name
|
59
|
+
when String
|
60
|
+
self[:slug] = list_id_or_screen_name
|
61
|
+
end
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module GooglePlus
|
4
|
+
module Creatable
|
5
|
+
|
6
|
+
# Time when the object was created on GooglePlus
|
7
|
+
#
|
8
|
+
# @return [Time]
|
9
|
+
def created_at
|
10
|
+
@created_at ||= Time.parse(@attrs['created_at']) unless @attrs['created_at'].nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'active_support/core_ext/kernel/singleton_class'
|
2
|
+
require 'google_plus/base'
|
3
|
+
|
4
|
+
module GooglePlus
|
5
|
+
class Cursor < GooglePlus::Base
|
6
|
+
attr_reader :collection
|
7
|
+
lazy_attr_reader :next_cursor, :previous_cursor
|
8
|
+
alias :next :next_cursor
|
9
|
+
alias :previous :previous_cursor
|
10
|
+
|
11
|
+
# Initializes a new Cursor object
|
12
|
+
#
|
13
|
+
# @param attrs [Hash]
|
14
|
+
# @params method [String, Symbol] The name of the method to return the collection
|
15
|
+
# @params klass [Class] The class to instantiate object in the collection
|
16
|
+
# @return [GooglePlus::Cursor]
|
17
|
+
def initialize(attrs, method, klass=nil)
|
18
|
+
super(attrs)
|
19
|
+
@collection = Array(attrs[method.to_s]).map do |item|
|
20
|
+
if klass
|
21
|
+
klass.new(item)
|
22
|
+
else
|
23
|
+
item
|
24
|
+
end
|
25
|
+
end
|
26
|
+
singleton_class.class_eval do
|
27
|
+
alias_method method.to_sym, :collection
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Boolean]
|
32
|
+
def first?
|
33
|
+
previous_cursor.zero?
|
34
|
+
end
|
35
|
+
alias :first :first?
|
36
|
+
|
37
|
+
# @return [Boolean]
|
38
|
+
def last?
|
39
|
+
next_cursor.zero?
|
40
|
+
end
|
41
|
+
alias :last :last?
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'google_plus/base'
|
2
|
+
#require 'google_plus/creatable'
|
3
|
+
#require 'google_plus/user'
|
4
|
+
|
5
|
+
module GooglePlus
|
6
|
+
class DirectMessage < GooglePlus::Base
|
7
|
+
include GooglePlus::Creatable
|
8
|
+
lazy_attr_reader :id, :text
|
9
|
+
|
10
|
+
# @param other [Twiter::DirectMessage]
|
11
|
+
# @return [Boolean]
|
12
|
+
def ==(other)
|
13
|
+
super || (other.class == self.class && other.id == self.id)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [GooglePlus::User]
|
17
|
+
def recipient
|
18
|
+
@recipient ||= GooglePlus::User.new(@attrs['recipient']) unless @attrs['recipient'].nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [GooglePlus::User]
|
22
|
+
def sender
|
23
|
+
@sender ||= GooglePlus::User.new(@attrs['sender']) unless @attrs['sender'].nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module GooglePlus
|
2
|
+
# Custom error class for rescuing from all GooglePlus errors
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :http_headers
|
5
|
+
|
6
|
+
# Initializes a new Error object
|
7
|
+
#
|
8
|
+
# @param message [String]
|
9
|
+
# @param http_headers [Hash]
|
10
|
+
# @return [Twitter::Error]
|
11
|
+
def initialize(message, http_headers)
|
12
|
+
@http_headers = Hash[http_headers]
|
13
|
+
super(message)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Time]
|
17
|
+
def ratelimit_reset
|
18
|
+
Time.at(@http_headers.values_at('x-ratelimit-reset', 'X-RateLimit-Reset').detect{|value| value}.to_i)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [Integer]
|
22
|
+
def ratelimit_limit
|
23
|
+
@http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect{|value| value}.to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Integer]
|
27
|
+
def ratelimit_remaining
|
28
|
+
@http_headers.values_at('x-ratelimit-remaining', 'X-RateLimit-Remaining').detect{|value| value}.to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Integer]
|
32
|
+
def retry_after
|
33
|
+
[(ratelimit_reset - Time.now).ceil, 0].max
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'google_plus/point'
|
2
|
+
require 'google_plus/polygon'
|
3
|
+
|
4
|
+
module GooglePlus
|
5
|
+
class GeoFactory
|
6
|
+
|
7
|
+
# Instantiates a new geo object
|
8
|
+
#
|
9
|
+
# @param attrs [Hash]
|
10
|
+
# @raise [ArgumentError] Error raised when supplied argument is missing a type key.
|
11
|
+
# @return [GooglePlus::Point, GooglePlus::Polygon]
|
12
|
+
def self.new(geo={})
|
13
|
+
type = geo['type']
|
14
|
+
if type
|
15
|
+
GooglePlus.const_get(type.capitalize.to_sym).new(geo)
|
16
|
+
else
|
17
|
+
raise ArgumentError, "argument must have a type key"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module GooglePlus
|
2
|
+
# Defines HTTP request methods
|
3
|
+
module Request
|
4
|
+
# Perform an HTTP DELETE request
|
5
|
+
def delete(path, params={}, options={})
|
6
|
+
request(:delete, path, params, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Perform an HTTP GET request
|
10
|
+
def get(path, params={}, options={})
|
11
|
+
request(:get, path, params, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Perform an HTTP POST request
|
15
|
+
def post(path, params={}, options={})
|
16
|
+
request(:post, path, params, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Perform an HTTP request
|
22
|
+
def request(method, path, params, options)
|
23
|
+
response = connection(options).send(method) do |request|
|
24
|
+
case method.to_sym
|
25
|
+
when :delete, :get
|
26
|
+
request.url(path, params)
|
27
|
+
when :post
|
28
|
+
request.path = path
|
29
|
+
request.body = params unless params.empty?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
options[:raw] ? response : response.body
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module GooglePlus
|
4
|
+
module Request
|
5
|
+
class Gateway < Faraday::Middleware
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
url = env[:url].dup
|
9
|
+
url.host = @gateway
|
10
|
+
env[:url] = url
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(app, gateway)
|
15
|
+
@app, @gateway = app, gateway
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module GooglePlus
|
4
|
+
module Request
|
5
|
+
class MultipartWithFile < Faraday::Middleware
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
if env[:body].is_a?(Hash)
|
9
|
+
env[:body].each do |key, value|
|
10
|
+
if value.is_a?(File)
|
11
|
+
env[:body][key] = Faraday::UploadIO.new(value, mime_type(value.path), value.path)
|
12
|
+
elsif value.is_a?(Hash) && (value['io'].is_a?(IO) || value['io'].is_a?(StringIO))
|
13
|
+
env[:body][key] = Faraday::UploadIO.new(value['io'], mime_type('.'+value['type']), '')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def mime_type(path)
|
23
|
+
case path
|
24
|
+
when /\.jpe?g/i
|
25
|
+
'image/jpeg'
|
26
|
+
when /\.gif$/i
|
27
|
+
'image/gif'
|
28
|
+
when /\.png$/i
|
29
|
+
'image/png'
|
30
|
+
else
|
31
|
+
'application/octet-stream'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|