GooglePlus 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.document +5 -0
  2. data/Gemfile +23 -0
  3. data/Gemfile.lock +56 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +46 -0
  7. data/VERSION +1 -0
  8. data/lib/GooglePlus.rb +26 -0
  9. data/lib/google_plus/api.rb +27 -0
  10. data/lib/google_plus/authenticatable.rb +25 -0
  11. data/lib/google_plus/base.rb +39 -0
  12. data/lib/google_plus/client.rb +29 -0
  13. data/lib/google_plus/client/activity.rb +10 -0
  14. data/lib/google_plus/client/comments.rb +10 -0
  15. data/lib/google_plus/client/users.rb +22 -0
  16. data/lib/google_plus/config.rb +103 -0
  17. data/lib/google_plus/configuration.rb +21 -0
  18. data/lib/google_plus/connection.rb +44 -0
  19. data/lib/google_plus/core_ext/hash.rb +66 -0
  20. data/lib/google_plus/creatable.rb +15 -0
  21. data/lib/google_plus/cursor.rb +45 -0
  22. data/lib/google_plus/direct_message.rb +28 -0
  23. data/lib/google_plus/error.rb +38 -0
  24. data/lib/google_plus/error/bad_gateway.rb +0 -0
  25. data/lib/google_plus/error/bad_request.rb +0 -0
  26. data/lib/google_plus/error/client_error.rb +8 -0
  27. data/lib/google_plus/error/enhance_your_calm.rb +0 -0
  28. data/lib/google_plus/error/forbidden.rb +8 -0
  29. data/lib/google_plus/error/internal_server_error.rb +0 -0
  30. data/lib/google_plus/error/not_acceptable.rb +0 -0
  31. data/lib/google_plus/error/not_found.rb +0 -0
  32. data/lib/google_plus/error/service_unavailable.rb +0 -0
  33. data/lib/google_plus/error/unauthorized.rb +8 -0
  34. data/lib/google_plus/geo_factory.rb +23 -0
  35. data/lib/google_plus/metadata.rb +8 -0
  36. data/lib/google_plus/request.rb +37 -0
  37. data/lib/google_plus/request/gateway.rb +21 -0
  38. data/lib/google_plus/request/multipart_with_file.rb +38 -0
  39. data/lib/google_plus/request/oauth.rb +27 -0
  40. data/lib/google_plus/request/phoenix.rb +23 -0
  41. data/lib/google_plus/response/parse_json.rb +24 -0
  42. data/lib/google_plus/response/raise_client_error.rb +54 -0
  43. data/lib/google_plus/response/raise_server_error.rb +30 -0
  44. data/lib/google_plus/size.rb +17 -0
  45. data/lib/google_plus/status.rb +87 -0
  46. data/lib/google_plus/user.rb +65 -0
  47. data/lib/google_plus/version.rb +31 -0
  48. data/test/helper.rb +19 -0
  49. data/test/test_GooglePlus.rb +14 -0
  50. metadata +255 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'faraday'
6
+ gem 'simple_oauth'
7
+ gem 'multi_json'
8
+ gem 'activesupport'
9
+ gem 'awesome_print'
10
+ gem "ruby-debug19"
11
+ gem "ruby-debug-ide"
12
+
13
+ # Add dependencies to develop your gem here.
14
+ # Include everything needed to run rake, tests, features, etc.
15
+ group :development, :test do
16
+ gem "minitest", ">= 0"
17
+ gem "yard", "~> 0.6.0"
18
+ gem "bundler", "~> 1.0.0"
19
+ gem "jeweler", "~> 1.5.2"
20
+ gem "rcov", ">= 0"
21
+ gem "ruby-debug19"
22
+ gem "ruby-debug-ide"
23
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.0)
5
+ addressable (2.2.6)
6
+ archive-tar-minitar (0.5.2)
7
+ awesome_print (0.4.0)
8
+ columnize (0.3.4)
9
+ faraday (0.7.5)
10
+ addressable (~> 2.2.6)
11
+ multipart-post (~> 1.1.3)
12
+ rack (< 2, >= 1.1.0)
13
+ git (1.2.5)
14
+ jeweler (1.5.2)
15
+ bundler (~> 1.0.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ linecache19 (0.5.12)
19
+ ruby_core_source (>= 0.1.4)
20
+ minitest (2.6.2)
21
+ multi_json (1.0.3)
22
+ multipart-post (1.1.3)
23
+ rack (1.3.5)
24
+ rake (0.9.2.2)
25
+ rcov (0.9.11)
26
+ ruby-debug-base19 (0.11.25)
27
+ columnize (>= 0.3.1)
28
+ linecache19 (>= 0.5.11)
29
+ ruby_core_source (>= 0.1.4)
30
+ ruby-debug-ide (0.4.16)
31
+ rake (>= 0.8.1)
32
+ ruby-debug19 (0.11.6)
33
+ columnize (>= 0.3.1)
34
+ linecache19 (>= 0.5.11)
35
+ ruby-debug-base19 (>= 0.11.19)
36
+ ruby_core_source (0.1.5)
37
+ archive-tar-minitar (>= 0.5.2)
38
+ simple_oauth (0.1.5)
39
+ yard (0.6.8)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ activesupport
46
+ awesome_print
47
+ bundler (~> 1.0.0)
48
+ faraday
49
+ jeweler (~> 1.5.2)
50
+ minitest
51
+ multi_json
52
+ rcov
53
+ ruby-debug-ide
54
+ ruby-debug19
55
+ simple_oauth
56
+ yard (~> 0.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Eric Steen, John Nunemaker, Wynn Netherland, Erik Michaels-Ober, Steve Richert
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,19 @@
1
+ = GooglePlus
2
+
3
+ Ruby wrapper for GooglePlus API heavily inspired by the twitter gem.
4
+
5
+ == Contributing to GooglePlus
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 rubycoder1. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "GooglePlus"
16
+ gem.homepage = "http://github.com/rubycoder1/GooglePlus"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{A Ruby wrapper for the Google+ API}
19
+ gem.description = %Q{Ruby wrapper for GooglePlus API heavily inspired by the twitter gem.}
20
+ gem.email = "rubycoder1@gmail.com"
21
+ gem.authors = ["rubycoder1"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'yard'
46
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
data/lib/GooglePlus.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'google_plus/client'
2
+ require 'google_plus/config'
3
+
4
+ module GooglePlus
5
+ extend Config
6
+ class << self
7
+ # Alias for GooglePlus::Client.new
8
+ #
9
+ # @return [GooglePlus::Client]
10
+ def new(options={})
11
+ GooglePlus::Client.new(options)
12
+ end
13
+
14
+ # Delegate to GooglePlus::Client
15
+ def method_missing(method, *args, &block)
16
+ return super unless new.respond_to?(method)
17
+ new.send(method, *args, &block)
18
+ end
19
+
20
+ def respond_to?(method, include_private=false)
21
+ new.respond_to?(method, include_private) || super(method, include_private)
22
+ end
23
+ end
24
+ end
25
+
26
+
@@ -0,0 +1,27 @@
1
+ require 'google_plus/authenticatable'
2
+ require 'google_plus/config'
3
+ require 'google_plus/connection'
4
+ require 'google_plus/request'
5
+
6
+ module GooglePlus
7
+ class API
8
+ include Authenticatable
9
+ include Connection
10
+ include Request
11
+
12
+ attr_accessor *Config::VALID_OPTIONS_KEYS
13
+
14
+ # Initializes a new API object
15
+ #
16
+ # @param attrs [Hash]
17
+ # @return [GooglePlus::API]
18
+ def initialize(attrs={})
19
+ attrs = GooglePlus.options.merge(attrs)
20
+ Config::VALID_OPTIONS_KEYS.each do |key|
21
+ instance_variable_set("@#{key}".to_sym, attrs[key])
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+
@@ -0,0 +1,25 @@
1
+ module GooglePlus
2
+ module Authenticatable
3
+
4
+ # Credentials hash
5
+ #
6
+ # @return [Hash]
7
+ def credentials
8
+ {
9
+ :consumer_key => consumer_key,
10
+ :consumer_secret => consumer_secret,
11
+ :token => oauth_token,
12
+ :token_secret => oauth_token_secret,
13
+ }
14
+ end
15
+
16
+ # Check whether credentials are present
17
+ #
18
+ # @return [Boolean]
19
+ def credentials?
20
+ credentials.values.all?
21
+ end
22
+
23
+ end
24
+ end
25
+
@@ -0,0 +1,39 @@
1
+ module GooglePlus
2
+ class Base
3
+ attr_accessor :attrs
4
+ alias :to_hash :attrs
5
+
6
+ # Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
7
+ #
8
+ # @overload self.lazy_attr_reader(attr)
9
+ # @param attr [Symbol]
10
+ # @overload self.lazy_attr_reader(attrs)
11
+ # @param attrs [Array<Symbol>]
12
+ def self.lazy_attr_reader(*attrs)
13
+ attrs.each do |attribute|
14
+ class_eval do
15
+ define_method attribute do
16
+ @attrs[attribute.to_s]
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ # Initializes a new Base object
23
+ #
24
+ # @param attrs [Hash]
25
+ # @return [GooglePlus::Base]
26
+ def initialize(attrs={})
27
+ @attrs = attrs.dup
28
+ end
29
+
30
+ # Initializes a new Base object
31
+ #
32
+ # @param method [String, Symbol] Message to send to the object
33
+ def [](method)
34
+ self.__send__(method.to_sym)
35
+ end
36
+
37
+ end
38
+ end
39
+
@@ -0,0 +1,29 @@
1
+ require 'google_plus/api'
2
+ require 'google_plus/configuration'
3
+ require 'google_plus/cursor'
4
+ #require 'google_plus/direct_message'
5
+
6
+ module GooglePlus
7
+ # Wrapper for the GooglePlus REST API
8
+ #
9
+ # @note All methods have been separated into modules
10
+ # @see https://developers.google.com/+/overview
11
+ class Client < API
12
+
13
+ # Require client method modules after initializing the Client class in
14
+ # order to avoid a superclass mismatch error, allowing those modules to be
15
+ # Client-namespaced.
16
+ require 'google_plus/client/users'
17
+ require 'google_plus/client/activity'
18
+ require 'google_plus/client/comments'
19
+
20
+
21
+ alias :api_endpoint :endpoint
22
+
23
+ include GooglePlus::Client::Users
24
+ include GooglePlus::Client::Activity
25
+ include GooglePlus::Client::Comments
26
+
27
+ end
28
+ end
29
+
@@ -0,0 +1,10 @@
1
+ module GooglePlus
2
+ class Client
3
+ # Defines methods related to users activities
4
+ module Activity
5
+
6
+ end
7
+
8
+ end
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ module GooglePlus
2
+ class Client
3
+ # Defines methods related to users comments
4
+ module Comments
5
+
6
+ end
7
+
8
+ end
9
+ end
10
+
@@ -0,0 +1,22 @@
1
+ require 'google_plus/core_ext/hash'
2
+ require 'google_plus/error/not_found'
3
+ require 'google_plus/user'
4
+
5
+ module GooglePlus
6
+ class Client
7
+ # Defines methods related to users
8
+ module Users
9
+
10
+ def user(*args)
11
+ options = args.last.is_a?(Hash) ? args.pop : {}
12
+ user = args.pop || get_screen_name
13
+ options.merge_user!(user)
14
+ user = get("/plus/v1/people/#{user}", options)
15
+ GooglePlus::User.new(user)
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+ end
22
+
@@ -0,0 +1,103 @@
1
+ require 'google_plus/version'
2
+
3
+ module GooglePlus
4
+ # Defines constants and methods related to configuration
5
+ module Config
6
+
7
+ # The HTTP connection adapter that will be used to connect if none is set
8
+ DEFAULT_ADAPTER = :net_http
9
+
10
+ # The Faraday connection options if none is set
11
+ DEFAULT_CONNECTION_OPTIONS = {}
12
+
13
+ # The consumer key if none is set
14
+ DEFAULT_CONSUMER_KEY = nil
15
+
16
+ # The consumer secret if none is set
17
+ DEFAULT_CONSUMER_SECRET = nil
18
+
19
+ # The endpoint that will be used to connect if none is set
20
+ #
21
+ # @note This is configurable in case you want to use HTTP instead of HTTPS, specify a different API version, or use a GooglePlus-compatible endpoint.
22
+ DEFAULT_ENDPOINT = 'https://www.googleapis.com/plus/v1'
23
+
24
+ # The gateway server if none is set
25
+ DEFAULT_GATEWAY = nil
26
+
27
+ # This endpoint will be used by default when updating statuses with media
28
+ DEFAULT_MEDIA_ENDPOINT = 'https://www.googleapis.com'
29
+
30
+ # The oauth token if none is set
31
+ DEFAULT_OAUTH_TOKEN = nil
32
+
33
+ # The oauth token secret if none is set
34
+ DEFAULT_OAUTH_TOKEN_SECRET = nil
35
+
36
+ # The proxy server if none is set
37
+ DEFAULT_PROXY = nil
38
+
39
+ # The search endpoint that will be used to connect if none is set
40
+ #
41
+ # @note This is configurable in case you want to use HTTP instead of HTTPS or use a GooglePlus-compatible endpoint.
42
+ # @see http://status.net/wiki/GooglePlus-compatible_API
43
+ DEFAULT_SEARCH_ENDPOINT = 'https://www.googleapis.com'
44
+
45
+ # The value sent in the 'User-Agent' header if none is set
46
+ DEFAULT_USER_AGENT = "GooglePlus Ruby Gem #{GooglePlus::Version}"
47
+
48
+ # An array of valid keys in the options hash when configuring a {GooglePlus::API}
49
+ VALID_OPTIONS_KEYS = [
50
+ :adapter,
51
+ :connection_options,
52
+ :consumer_key,
53
+ :consumer_secret,
54
+ :endpoint,
55
+ :gateway,
56
+ :oauth_token,
57
+ :oauth_token_secret,
58
+ :proxy,
59
+ :search_endpoint,
60
+ :user_agent,
61
+ :media_endpoint
62
+ ]
63
+
64
+ attr_accessor *VALID_OPTIONS_KEYS
65
+
66
+ # When this module is extended, set all configuration options to their default values
67
+ def self.extended(base)
68
+ base.reset
69
+ end
70
+
71
+ # Convenience method to allow configuration options to be set in a block
72
+ def configure
73
+ yield self
74
+ self
75
+ end
76
+
77
+ # Create a hash of options and their values
78
+ def options
79
+ options = {}
80
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
81
+ options
82
+ end
83
+
84
+ # Reset all configuration options to defaults
85
+ def reset
86
+ self.adapter = DEFAULT_ADAPTER
87
+ self.connection_options = DEFAULT_CONNECTION_OPTIONS
88
+ self.consumer_key = DEFAULT_CONSUMER_KEY
89
+ self.consumer_secret = DEFAULT_CONSUMER_SECRET
90
+ self.endpoint = DEFAULT_ENDPOINT
91
+ self.gateway = DEFAULT_GATEWAY
92
+ self.media_endpoint = DEFAULT_MEDIA_ENDPOINT
93
+ self.oauth_token = DEFAULT_OAUTH_TOKEN
94
+ self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET
95
+ self.proxy = DEFAULT_PROXY
96
+ self.search_endpoint = DEFAULT_SEARCH_ENDPOINT
97
+ self.user_agent = DEFAULT_USER_AGENT
98
+ self
99
+ end
100
+
101
+ end
102
+ end
103
+