google_simple_api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.travis.yml +16 -0
- data/.travis.yml~ +19 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +201 -0
- data/README.md +83 -0
- data/Rakefile +2 -0
- data/google_simple_api.gemspec +30 -0
- data/lib/google_simple_api.rb +46 -0
- data/lib/google_simple_api/authorizer.rb +50 -0
- data/lib/google_simple_api/manager.rb +75 -0
- data/lib/google_simple_api/settings.rb +54 -0
- data/lib/google_simple_api/version.rb +19 -0
- data/spec/google_simple_api/authorizer_spec.rb +130 -0
- data/spec/google_simple_api/manager_spec.rb +129 -0
- data/spec/google_simple_api/settings_spec.rb +56 -0
- data/spec/google_simple_api_spec.rb +77 -0
- data/spec/spec_helper.rb +21 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OThjNTI5ZDA0M2VhMzYxOTRkOTM5YzdmMWI3YmIzZTQ2NGUxMTFmOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NmVjMzhlZTNhMTc4MGFhOWQwNmQ2ZjUzNmVhNWZmOTMzZTMxNWExOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTFhYTgxNmY4MGE1ODViYmFjZjdlY2M1M2MwYzY1NjdmNmFhNjZjNDA2NWFj
|
10
|
+
YmIyMDgxYjVkYjgwNTk5MTcyMTFiNTZlMzkxYzkxNzcxNzlmM2VmODYyNDlh
|
11
|
+
Y2YxOWZlODY3YWUyOTIyMjE3MDVkZTdkMzBmYTIwNmEzMDk1NDM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjU5MzJhYjE5MDliMTNhMDg1MmRiNzc2Y2Y4MDMzZjBhZjRhZTcwMWI5OTY4
|
14
|
+
MDVmMTZkNjFlMDI2OWIyYTE2MTdiNTdjMDZiMzc4NWZhNzExMDg1OWZlNjg3
|
15
|
+
NDZkMGU5NjRlYWE1NzBiYjUxYWE3OTNlODBiODc5NTg4ZjlhMzI=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.travis.yml~
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright 2014 Bruno Goes de Meira
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/google_simple_api.svg)](http://badge.fury.io/rb/google_simple_api)
|
2
|
+
[![Build Status](https://travis-ci.org/brunomeira/google_simple_api.svg?branch=master)](https://travis-ci.org/brunomeira/google_simple_api)
|
3
|
+
# GoogleSimpleApi
|
4
|
+
|
5
|
+
This gem wraps up calls executed by [google-api-ruby-client](https://github.com/google/google-api-ruby-client)
|
6
|
+
and makes it simple for you to be authorized and access the data provided by Google APIs.
|
7
|
+
|
8
|
+
## Getting Started
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'google_simple_api'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install google_simple_api
|
21
|
+
|
22
|
+
## How to Use
|
23
|
+
|
24
|
+
To use the gem you need to have a project set up on Google. In order to do it so, you have to visit [https://console.developers.google.com](https://console.developers.google.com), allow access to the required APIs and ,lastly, create a new Client ID with a callback URL associated with it.
|
25
|
+
|
26
|
+
After you complete the pre-setting process, you can go back to your app and work on the following steps:
|
27
|
+
|
28
|
+
#### First time use
|
29
|
+
1. Create a *google_simple_api.rb* in /initializers
|
30
|
+
|
31
|
+
GoogleSimpleApi.setup do |config|
|
32
|
+
config.name = "test" #The name of your application
|
33
|
+
config.version = "1" #The current version of your application
|
34
|
+
config.api = "drive" #The api that will be used.
|
35
|
+
config.api_version = "v2" #If not specified, it will defaults to v1
|
36
|
+
config.client_id = "XXXXXXXXXXXXXXXX" #Value provided in the Credentials Section.
|
37
|
+
config.client_secret = "XXXXXXXXXXXXXX" #Value provided in the Credentials Section.
|
38
|
+
config.scope = "drive" # The scope(s) required to use the api, it can be an Array.
|
39
|
+
end
|
40
|
+
|
41
|
+
2. You now have to send the user to Google's authorization page. Use:
|
42
|
+
|
43
|
+
GoogleSimpleApi.process.authorize_url("specified callback")
|
44
|
+
|
45
|
+
to receive the proper URL and then redirect the user to it.
|
46
|
+
|
47
|
+
3. If the user accepts the access to the app, Google will redirect you back to the "specified callback" along with a "code" parameter. Use this code to get a valid token.
|
48
|
+
|
49
|
+
manager = GoogleSimpleApi.process
|
50
|
+
manager.get_token(params[:code])
|
51
|
+
For further use, You should store the values returned from this call.
|
52
|
+
|
53
|
+
4. To make any call to the api, you have to invoke:
|
54
|
+
|
55
|
+
manager.execute("method.name", {key1: "value", key2:"value2"}) # Example: manager.execute("files.list")
|
56
|
+
where the first parameter is the action that will be executed and the second is any required or optional parameter.
|
57
|
+
|
58
|
+
5. I hope you enjoy it.
|
59
|
+
|
60
|
+
#### Using refresh token to request token
|
61
|
+
|
62
|
+
Tokens may expire due a variety of different reasons. If you have stored the user's refresh token then you won't need to ask
|
63
|
+
the users to go through all the acceptance process again (This is true for cases where the users didn't remove access to the app, you didn't change the scope of the app, or etc...). In order to do it so, you only need to call:
|
64
|
+
|
65
|
+
manager = GoogleSimpleApi.process
|
66
|
+
manager.get_token("refresh_token", true) # The second parameter tells the function you are passing a refresh_token
|
67
|
+
|
68
|
+
## Further Reading
|
69
|
+
If you are having trouble to understand the gem or want something more customizable, check the links below:
|
70
|
+
|
71
|
+
1. [google-api-ruby-client](https://github.com/google/google-api-ruby-client) - GoogleSimpleApi is based on this gem. If you need something more complex than get a token and access the api, you should check it out.
|
72
|
+
|
73
|
+
2. [Google OAUTH process](https://developers.google.com/accounts/docs/OAuth2WebServer) If you need more background on how the authorization process works.
|
74
|
+
|
75
|
+
3. [APIs services](https://developers.google.com/apis-explorer) - Interesting resource, If you need to know which apis,services and scopes are available.
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. Fork it ( https://github.com/brunomeira/google_simple_api/fork )
|
80
|
+
2. Create your feature branch (`git checkout b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'google_simple_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "google_simple_api"
|
8
|
+
spec.version = GoogleSimpleApi::VERSION
|
9
|
+
spec.authors = ["Bruno Meira"]
|
10
|
+
spec.email = ["goesmeira@gmail.com"]
|
11
|
+
spec.summary = "Access data from Google APIs"
|
12
|
+
spec.description = "GoogleSimpleApi is a wrapper for Google APIs that makes it easy to access and receive data from it."
|
13
|
+
spec.homepage = "https://github.com/brunomeira/google-simple-api"
|
14
|
+
spec.license = "Apache 2.0"
|
15
|
+
spec.required_ruby_version = '>= 1.9.3'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "google-api-client", '~> 0.7'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "guard"
|
28
|
+
spec.add_development_dependency "guard-rspec"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
require "google/api_client"
|
15
|
+
|
16
|
+
require "google_simple_api/settings"
|
17
|
+
require "google_simple_api/authorizer"
|
18
|
+
require "google_simple_api/manager"
|
19
|
+
require "google_simple_api/version"
|
20
|
+
|
21
|
+
# @author Bruno Meira <goesmeira@gmail.com>
|
22
|
+
module GoogleSimpleApi
|
23
|
+
class << self
|
24
|
+
attr_reader :settings
|
25
|
+
end
|
26
|
+
|
27
|
+
# Prepares the api for initial use. It assigns variables and load dependencies.
|
28
|
+
# @yield [settings] Gets an instance of {GoogleSimpleApi::Settings} and assigns value to its attributes.
|
29
|
+
# @return [void]
|
30
|
+
def self.setup
|
31
|
+
yield(settings)
|
32
|
+
settings.load_api
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns an instance of #<tt>GoogleSimpleApi::Manager</tt>.
|
36
|
+
# @param access_token [String] a valid token.
|
37
|
+
# @return [GoogleSimpleApi::Manager] the object that handles authorization and api calls.
|
38
|
+
def self.process(access_token = nil)
|
39
|
+
GoogleSimpleApi::Manager.new(settings, access_token)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def self.settings
|
44
|
+
@settings ||= GoogleSimpleApi::Settings.new
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
# @author Bruno Meira <goesmeira@gmail.com>
|
15
|
+
module GoogleSimpleApi
|
16
|
+
class Authorizer
|
17
|
+
attr_reader :authorization
|
18
|
+
attr_reader :settings
|
19
|
+
|
20
|
+
def initialize(settings)
|
21
|
+
@settings = settings
|
22
|
+
@authorization = load_authorization
|
23
|
+
end
|
24
|
+
|
25
|
+
def callback=(callback)
|
26
|
+
@authorization.redirect_uri = callback
|
27
|
+
end
|
28
|
+
|
29
|
+
def code=(code)
|
30
|
+
@authorization.code = code
|
31
|
+
end
|
32
|
+
|
33
|
+
def access_token=(access_token)
|
34
|
+
@authorization.access_token = access_token
|
35
|
+
end
|
36
|
+
|
37
|
+
def refresh_token=(refresh_token)
|
38
|
+
@authorization.refresh_token = refresh_token
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def load_authorization
|
43
|
+
auth = settings.api_client.authorization
|
44
|
+
auth.client_id = settings.client_id
|
45
|
+
auth.client_secret = settings.client_secret
|
46
|
+
auth.scope = settings.scope.map { |elem| "https://www.googleapis.com/auth/#{elem}" }
|
47
|
+
auth
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
# @author Bruno Meira
|
15
|
+
module GoogleSimpleApi
|
16
|
+
class Manager
|
17
|
+
attr_reader :settings, :authorizer
|
18
|
+
|
19
|
+
def initialize(settings, access_token = nil)
|
20
|
+
@settings = settings
|
21
|
+
@authorizer = GoogleSimpleApi::Authorizer.new(settings)
|
22
|
+
@authorizer.access_token = access_token if access_token
|
23
|
+
end
|
24
|
+
|
25
|
+
# Builds an URL that will be used by users to allow access to the apis.
|
26
|
+
# @param callback_url [String] the URL that the user will be redirected back after approve or
|
27
|
+
# reject access to the api.
|
28
|
+
# @return [String] the complete URL which the users need to be send to.
|
29
|
+
def authorize_url(callback_url=nil)
|
30
|
+
@authorizer.callback=(callback_url)
|
31
|
+
@authorizer.authorization.authorization_uri.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
# Processes code param and returns a valid access_token.
|
35
|
+
# @param code [String] the code returned from {#authorize_url} or
|
36
|
+
# a previous stored refresh_token if <tt>refresh_token</tt> was true.
|
37
|
+
# @param refresh_token [Boolean] indicates if <tt>code</tt> is a refresh_token or a code from first access.
|
38
|
+
# @return [Hash] with all required data for the api access.
|
39
|
+
def get_token(code, refresh_token=false)
|
40
|
+
if refresh_token
|
41
|
+
authorizer.refresh_token=(code)
|
42
|
+
else
|
43
|
+
authorizer.code= code
|
44
|
+
end
|
45
|
+
|
46
|
+
authorizer.authorization.fetch_access_token!
|
47
|
+
end
|
48
|
+
|
49
|
+
# Executes call for the loaded api.
|
50
|
+
# @param action [String] the resource that will be called.
|
51
|
+
# @param parameters [Hash] the parameters associated with the action.
|
52
|
+
# @return an object that contains the result of the call.
|
53
|
+
def execute(action, parameters = {})
|
54
|
+
methods = split_method(action)
|
55
|
+
discovered_api = settings.discovered_api
|
56
|
+
api_client = settings.api_client
|
57
|
+
|
58
|
+
params = {
|
59
|
+
:api_method => chained_method_calls(methods, discovered_api),
|
60
|
+
:parameters => parameters
|
61
|
+
}
|
62
|
+
|
63
|
+
api_client.execute(params).data
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def chained_method_calls(methods, api)
|
68
|
+
methods.inject(api) { |e, method| e.send(method.underscore) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def split_method(method)
|
72
|
+
method.split(".")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
# @author Bruno Meira <goesmeira@gmail.com>
|
15
|
+
module GoogleSimpleApi
|
16
|
+
class Settings
|
17
|
+
|
18
|
+
attr_accessor :api, :api_client, :client_id, :client_secret,
|
19
|
+
:discovered_api, :name, :version, :scope, :api_version
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
@api = options[:api]
|
23
|
+
@client_id = options[:client_id]
|
24
|
+
@client_secret = options[:client_secret]
|
25
|
+
@name = options[:name]
|
26
|
+
@api_version = options[:api_version]
|
27
|
+
@version = options[:version]
|
28
|
+
@scope = [].push(options[:scope]).flatten
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_api
|
32
|
+
@api_client = load_api_client
|
33
|
+
@discovered_api = discover_api if @api_client
|
34
|
+
end
|
35
|
+
|
36
|
+
def scope=(value)
|
37
|
+
@scope = [].push(value).flatten
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def load_api_client
|
42
|
+
params = {
|
43
|
+
:application_name => @name,
|
44
|
+
:application_version => @version
|
45
|
+
}
|
46
|
+
|
47
|
+
Google::APIClient.new(params)
|
48
|
+
end
|
49
|
+
|
50
|
+
def discover_api
|
51
|
+
@api_client.discovered_api(@api, @api_version || "v1")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
module GoogleSimpleApi
|
15
|
+
MAJOR = 1
|
16
|
+
MINOR = 0
|
17
|
+
PATCH = 0
|
18
|
+
VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
|
19
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
require "spec_helper"
|
15
|
+
|
16
|
+
describe GoogleSimpleApi::Authorizer do
|
17
|
+
let(:name) { "test" }
|
18
|
+
let(:version) { "1.0.0" }
|
19
|
+
let(:api) { "plus" }
|
20
|
+
let(:client_id) { "123152412412" }
|
21
|
+
let(:client_secret) { "sad3121232" }
|
22
|
+
let(:api_version) { "v1" }
|
23
|
+
let(:params) do
|
24
|
+
{
|
25
|
+
:name => name, :version => version, :api => api,
|
26
|
+
:client_id => client_id, :client_secret => client_secret,
|
27
|
+
:api_version => api_version
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:settings) { GoogleSimpleApi::Settings.new(params) }
|
32
|
+
|
33
|
+
describe "Methods" do
|
34
|
+
before { settings.load_api }
|
35
|
+
|
36
|
+
describe "#initialize" do
|
37
|
+
it "calls #load_authorization" do
|
38
|
+
GoogleSimpleApi::Authorizer.any_instance.should_receive(:load_authorization).once
|
39
|
+
GoogleSimpleApi::Authorizer.new(settings)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#callback=" do
|
44
|
+
let(:authorizer) { GoogleSimpleApi::Authorizer.new(settings) }
|
45
|
+
subject { authorizer }
|
46
|
+
|
47
|
+
before { authorizer.settings.load_api }
|
48
|
+
|
49
|
+
it { should respond_to(:callback=).with(1).argument }
|
50
|
+
|
51
|
+
it "sets #redirect_uri value of authorization" do
|
52
|
+
expect {
|
53
|
+
authorizer.callback=("http://www.test.com")
|
54
|
+
}.to change { authorizer.authorization.redirect_uri }
|
55
|
+
end
|
56
|
+
|
57
|
+
it "doesn't change anything if callback is nil" do
|
58
|
+
expect {
|
59
|
+
authorizer.callback=(nil)
|
60
|
+
}.to_not change { authorizer.authorization.redirect_uri }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#code=" do
|
65
|
+
let(:authorizer) { GoogleSimpleApi::Authorizer.new(settings) }
|
66
|
+
let(:code) { "123456" }
|
67
|
+
subject { authorizer }
|
68
|
+
|
69
|
+
before { authorizer.settings.load_api }
|
70
|
+
|
71
|
+
it { should respond_to(:code=).with(1).argument }
|
72
|
+
|
73
|
+
it "sets #code value of authorization" do
|
74
|
+
expect {
|
75
|
+
authorizer.code= code
|
76
|
+
}.to change { authorizer.authorization.code }
|
77
|
+
end
|
78
|
+
|
79
|
+
it "doesn't change anything if code is nil" do
|
80
|
+
expect {
|
81
|
+
authorizer.code= nil
|
82
|
+
}.to_not change { authorizer.authorization.code }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#set_access_token" do
|
87
|
+
let(:authorizer) { GoogleSimpleApi::Authorizer.new(settings) }
|
88
|
+
let(:access_token) { "123456" }
|
89
|
+
subject { authorizer }
|
90
|
+
|
91
|
+
before { authorizer.settings.load_api }
|
92
|
+
|
93
|
+
it { should respond_to(:access_token=).with(1).argument }
|
94
|
+
|
95
|
+
it "sets #access_token value of authorization" do
|
96
|
+
expect {
|
97
|
+
authorizer.access_token= access_token
|
98
|
+
}.to change { authorizer.authorization.access_token }
|
99
|
+
end
|
100
|
+
|
101
|
+
it "doesn't change anything if access_token is nil" do
|
102
|
+
expect {
|
103
|
+
authorizer.access_token= nil
|
104
|
+
}.to_not change { authorizer.authorization.access_token }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#refresh_token=" do
|
109
|
+
let(:authorizer) { GoogleSimpleApi::Authorizer.new(settings) }
|
110
|
+
let(:refresh_token) { "123456" }
|
111
|
+
subject { authorizer }
|
112
|
+
|
113
|
+
before { authorizer.settings.load_api }
|
114
|
+
|
115
|
+
it { should respond_to(:refresh_token=).with(1).argument }
|
116
|
+
|
117
|
+
it "sets #refresh_token value of authorization" do
|
118
|
+
expect {
|
119
|
+
authorizer.refresh_token=(refresh_token)
|
120
|
+
}.to change { authorizer.authorization.refresh_token }
|
121
|
+
end
|
122
|
+
|
123
|
+
it "sets grant type to refresh_token" do
|
124
|
+
expect {
|
125
|
+
authorizer.refresh_token=(refresh_token)
|
126
|
+
}.to change { authorizer.authorization.grant_type }.to("refresh_token")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
require 'spec_helper'
|
15
|
+
|
16
|
+
describe GoogleSimpleApi::Manager do
|
17
|
+
let(:name) { "test" }
|
18
|
+
let(:version) { "1.0.0" }
|
19
|
+
let(:api) { "plus" }
|
20
|
+
let(:client_id) { "123152412412" }
|
21
|
+
let(:client_secret) { "sad3121232" }
|
22
|
+
let(:params) do
|
23
|
+
{
|
24
|
+
:name => name, :version => version, :api => api,
|
25
|
+
:client_id => client_id, :client_secret => client_secret
|
26
|
+
}
|
27
|
+
end
|
28
|
+
let(:settings) { GoogleSimpleApi::Settings.new(params) }
|
29
|
+
|
30
|
+
before { settings.load_api }
|
31
|
+
|
32
|
+
describe "Instantiation process" do
|
33
|
+
it "instantiates an authorizer" do
|
34
|
+
instance = GoogleSimpleApi::Manager.new(settings)
|
35
|
+
instance.authorizer.should be_a GoogleSimpleApi::Authorizer
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with access token" do
|
39
|
+
let(:code) { "1232222" }
|
40
|
+
it "instantiates code" do
|
41
|
+
GoogleSimpleApi::Authorizer.any_instance.should_receive(:access_token=).with(code).once
|
42
|
+
GoogleSimpleApi::Manager.new(settings, code)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "without access token" do
|
47
|
+
it "doesn't instantiate code" do
|
48
|
+
GoogleSimpleApi::Authorizer.any_instance.should_not_receive(:access_token=)
|
49
|
+
GoogleSimpleApi::Manager.new(settings)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "Methods" do
|
55
|
+
subject { GoogleSimpleApi::Manager.new(settings) }
|
56
|
+
|
57
|
+
describe "#authorize_url" do
|
58
|
+
let(:url) { "http://www.test.com" }
|
59
|
+
|
60
|
+
it { should respond_to :authorize_url }
|
61
|
+
|
62
|
+
it "updates authorization callback uri" do
|
63
|
+
subject.authorize_url(url).should be_a String
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#get_token" do
|
68
|
+
let(:code) { "123456" }
|
69
|
+
|
70
|
+
it { should respond_to :get_token }
|
71
|
+
|
72
|
+
context "without refresh token" do
|
73
|
+
it "calls #settings.code=" do
|
74
|
+
subject.authorizer.authorization.stub(:fetch_access_token! => true)
|
75
|
+
subject.authorizer.should_receive(:code=).once
|
76
|
+
subject.get_token(code)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "calls fetch_access_token!" do
|
80
|
+
subject.authorizer.authorization.stub(:fetch_access_token! => true)
|
81
|
+
subject.authorizer.authorization.should_receive(:fetch_access_token!).once
|
82
|
+
subject.get_token(code)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "with refresh token" do
|
87
|
+
it "calls #settings.code=" do
|
88
|
+
subject.authorizer.authorization.stub(:fetch_access_token! => true)
|
89
|
+
subject.authorizer.should_receive(:refresh_token=).once
|
90
|
+
subject.get_token(code, true)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "calls fetch_access_token!" do
|
94
|
+
subject.authorizer.authorization.stub(:fetch_access_token! => true)
|
95
|
+
subject.authorizer.authorization.should_receive(:fetch_access_token!).once
|
96
|
+
subject.get_token(code, true)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#execute" do
|
102
|
+
let(:method) { "activities.list" }
|
103
|
+
before do
|
104
|
+
double_execute = double("Test", :data => "result")
|
105
|
+
subject.stub(:split_method => ["activities", "list"])
|
106
|
+
subject.stub(:chained_method_calls => "")
|
107
|
+
subject.stub_chain(:settings, :discovered_api).and_return({})
|
108
|
+
subject.stub_chain(:settings, :api_client, :execute).and_return(double_execute)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "calls #split_method once" do
|
112
|
+
subject.should_receive(:split_method).with(method).once
|
113
|
+
subject.execute(method)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "calls #chained_method_calls once" do
|
117
|
+
subject.should_receive(:chained_method_calls).
|
118
|
+
with(subject.send(:split_method), subject.settings.discovered_api).once
|
119
|
+
|
120
|
+
subject.execute(method)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "returns call from #settings.api_client.execute" do
|
124
|
+
subject.execute(method).should == "result"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
require "spec_helper"
|
15
|
+
|
16
|
+
describe GoogleSimpleApi::Settings do
|
17
|
+
let(:name) { "test" }
|
18
|
+
let(:version) { "1.0.0" }
|
19
|
+
let(:api) { "plus" }
|
20
|
+
let(:client_id) { "123152412412" }
|
21
|
+
let(:client_secret) { "sad3121232" }
|
22
|
+
let(:params) do
|
23
|
+
{
|
24
|
+
:name => name, :version => version, :api => api,
|
25
|
+
:client_id => client_id, :client_secret => client_secret
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "Methods" do
|
30
|
+
describe "#initialize" do
|
31
|
+
it "assigns values to #name, #version, #api, #client_id and #client_secret" do
|
32
|
+
settings = GoogleSimpleApi::Settings.new(params)
|
33
|
+
|
34
|
+
settings.name.should == name
|
35
|
+
settings.version.should == version
|
36
|
+
settings.api.should == api
|
37
|
+
settings.client_id.should == client_id
|
38
|
+
settings.client_secret.should == client_secret
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#load_api" do
|
43
|
+
it "calls #load_api_client" do
|
44
|
+
GoogleSimpleApi::Settings.any_instance.should_receive(:load_api_client).once
|
45
|
+
settings = GoogleSimpleApi::Settings.new(params)
|
46
|
+
settings.load_api
|
47
|
+
end
|
48
|
+
|
49
|
+
it "calls #discover_api" do
|
50
|
+
GoogleSimpleApi::Settings.any_instance.should_receive(:discover_api).once
|
51
|
+
settings = GoogleSimpleApi::Settings.new(params)
|
52
|
+
settings.load_api
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
require "spec_helper"
|
15
|
+
|
16
|
+
describe GoogleSimpleApi do
|
17
|
+
let(:name) { "test" }
|
18
|
+
let(:version) { "1.0.0" }
|
19
|
+
let(:api) { "plus" }
|
20
|
+
let(:api_version) { "v1" }
|
21
|
+
let(:client_id) { "123152412412" }
|
22
|
+
let(:client_secret) { "sad3121232" }
|
23
|
+
let(:scope) { "plus.me" }
|
24
|
+
|
25
|
+
let(:setup_call) do
|
26
|
+
GoogleSimpleApi.setup do |config|
|
27
|
+
config.name = name
|
28
|
+
config.version = version
|
29
|
+
config.api = api
|
30
|
+
config.api_version = api_version
|
31
|
+
config.client_id = client_id
|
32
|
+
config.client_secret = client_secret
|
33
|
+
config.scope = scope
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Methods" do
|
38
|
+
describe ".setup" do
|
39
|
+
it { GoogleSimpleApi.should respond_to :setup }
|
40
|
+
|
41
|
+
it "creates a valid instance of GoogleSimpleApi::Setting" do
|
42
|
+
setup_call
|
43
|
+
GoogleSimpleApi.settings.class.should == GoogleSimpleApi::Settings
|
44
|
+
GoogleSimpleApi.settings.name.should == name
|
45
|
+
GoogleSimpleApi.settings.version.should == version
|
46
|
+
GoogleSimpleApi.settings.api.should == api
|
47
|
+
GoogleSimpleApi.settings.api_version.should == api_version
|
48
|
+
GoogleSimpleApi.settings.client_id.should == client_id
|
49
|
+
GoogleSimpleApi.settings.client_secret.should == client_secret
|
50
|
+
end
|
51
|
+
|
52
|
+
it "loads api" do
|
53
|
+
GoogleSimpleApi.settings.should_receive(:load_api).once
|
54
|
+
setup_call
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".process" do
|
60
|
+
it { GoogleSimpleApi.should respond_to :process }
|
61
|
+
it { GoogleSimpleApi.process.should be_a GoogleSimpleApi::Manager }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
describe "full flow" do
|
67
|
+
let(:client_id) { "765210565694-ptflkrme0ef5rjjai8agg36h5mbj0fdv.apps.googleusercontent.com" }
|
68
|
+
let(:client_secret) { "2negC6yH_qkdLy_SX2J5VCNt" }
|
69
|
+
let(:authorization_url) { "http://localhost:3000/my/access_tokens/google_callback" }
|
70
|
+
|
71
|
+
it "creates an authorization URL" do
|
72
|
+
setup_call
|
73
|
+
GoogleSimpleApi.process.authorize_url(authorization_url).should be_a String
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#Copyright 2014 Bruno Goes de Meira
|
2
|
+
#Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
#you may not use this file except in compliance with the License.
|
4
|
+
#You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
#Unless required by applicable law or agreed to in writing, software
|
9
|
+
#distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
#See the License for the specific language governing permissions and
|
12
|
+
#limitations under the License.
|
13
|
+
|
14
|
+
require 'bundler/setup'
|
15
|
+
Bundler.setup
|
16
|
+
|
17
|
+
require 'google_simple_api'
|
18
|
+
|
19
|
+
#RSpec.configure do |config|
|
20
|
+
# # some (optional) config here
|
21
|
+
#end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_simple_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruno Meira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: google-api-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: GoogleSimpleApi is a wrapper for Google APIs that makes it easy to access
|
112
|
+
and receive data from it.
|
113
|
+
email:
|
114
|
+
- goesmeira@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .rspec
|
121
|
+
- .travis.yml
|
122
|
+
- .travis.yml~
|
123
|
+
- Gemfile
|
124
|
+
- Guardfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- google_simple_api.gemspec
|
129
|
+
- lib/google_simple_api.rb
|
130
|
+
- lib/google_simple_api/authorizer.rb
|
131
|
+
- lib/google_simple_api/manager.rb
|
132
|
+
- lib/google_simple_api/settings.rb
|
133
|
+
- lib/google_simple_api/version.rb
|
134
|
+
- spec/google_simple_api/authorizer_spec.rb
|
135
|
+
- spec/google_simple_api/manager_spec.rb
|
136
|
+
- spec/google_simple_api/settings_spec.rb
|
137
|
+
- spec/google_simple_api_spec.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
homepage: https://github.com/brunomeira/google-simple-api
|
140
|
+
licenses:
|
141
|
+
- Apache 2.0
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 1.9.3
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.0.3
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Access data from Google APIs
|
163
|
+
test_files:
|
164
|
+
- spec/google_simple_api/authorizer_spec.rb
|
165
|
+
- spec/google_simple_api/manager_spec.rb
|
166
|
+
- spec/google_simple_api/settings_spec.rb
|
167
|
+
- spec/google_simple_api_spec.rb
|
168
|
+
- spec/spec_helper.rb
|