google-api-client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,36 +16,40 @@ require 'spec_helper'
16
16
 
17
17
  require 'json'
18
18
  require 'google/api_client/parsers/json_parser'
19
+ require 'google/api_client/parsers/json/error_parser'
20
+ require 'google/api_client/parsers/json/pagination'
19
21
 
20
- describe Google::APIClient::JSONParser, 'generates json from hash' do
22
+ describe Google::APIClient::JSONParser, 'with error data' do
21
23
  before do
22
- @parser = Google::APIClient::JSONParser
23
- end
24
-
25
- it 'should translate simple hash to JSON string' do
26
- @parser.serialize('test' => 23).should == '{"test":23}'
27
- end
28
-
29
- it 'should translate simple nested into to nested JSON string' do
30
- @parser.serialize({
31
- 'test' => 23, 'test2' => {'foo' => 'baz', 12 => 3.14 }
32
- }).should ==
33
- '{"test2":{"12":3.14,"foo":"baz"},"test":23}'
24
+ @data = {
25
+ 'error' => {
26
+ 'code' => 401,
27
+ 'message' => 'Token invalid - Invalid AuthSub token.',
28
+ 'errors' => [
29
+ {
30
+ 'location' => 'Authorization',
31
+ 'domain' => 'global',
32
+ 'locationType' => 'header',
33
+ 'reason' => 'authError',
34
+ 'message' => 'Token invalid - Invalid AuthSub token.'
35
+ }
36
+ ]
37
+ }
38
+ }
34
39
  end
35
- end
36
40
 
37
- describe Google::APIClient::JSONParser, 'parses json string into hash' do
38
- before do
39
- @parser = Google::APIClient::JSONParser
41
+ it 'should correctly match as an error' do
42
+ parser = Google::APIClient::JSONParser.match(@data)
43
+ parser.should == Google::APIClient::JSON::ErrorParser
40
44
  end
41
45
 
42
- it 'should parse simple json string into hash' do
43
- @parser.parse('{"test":23}').should == {'test' => 23}
46
+ it 'should be automatically handled as an error when parsed' do
47
+ data = Google::APIClient::JSONParser.parse(@data)
48
+ data.should be_kind_of(Google::APIClient::JSON::ErrorParser)
44
49
  end
45
50
 
46
- it 'should parse nested json object into hash' do
47
- @parser.parse('{"test":23, "test2":{"bar":"baz", "foo":3.14}}').should == {
48
- 'test' => 23, 'test2' => {'bar' => 'baz', 'foo' => 3.14}
49
- }
51
+ it 'should correctly expose error message' do
52
+ data = Google::APIClient::JSONParser.parse(@data)
53
+ data.error.should == 'Token invalid - Invalid AuthSub token.'
50
54
  end
51
55
  end
@@ -36,7 +36,7 @@ shared_examples_for 'configurable user agent' do
36
36
  it 'should not allow the user agent to be used with bogus values' do
37
37
  (lambda do
38
38
  @client.user_agent = 42
39
- @client.transmit_request(
39
+ @client.transmit(
40
40
  ['GET', 'http://www.google.com/', [], []]
41
41
  )
42
42
  end).should raise_error(TypeError)
@@ -53,7 +53,7 @@ shared_examples_for 'configurable user agent' do
53
53
  end
54
54
  [200, [], ['']]
55
55
  end
56
- @client.transmit_request(request, adapter)
56
+ @client.transmit(request, adapter)
57
57
  end
58
58
  end
59
59
 
@@ -63,11 +63,7 @@ describe Google::APIClient do
63
63
  end
64
64
 
65
65
  it 'should make its version number available' do
66
- ::Google::APIClient::VERSION::STRING.should be_instance_of(String)
67
- end
68
-
69
- it 'should use the default JSON parser' do
70
- @client.parser.should be(Google::APIClient::JSONParser)
66
+ Google::APIClient::VERSION::STRING.should be_instance_of(String)
71
67
  end
72
68
 
73
69
  it 'should default to OAuth 2' do
@@ -104,26 +100,4 @@ describe Google::APIClient do
104
100
  # TODO
105
101
  it_should_behave_like 'configurable user agent'
106
102
  end
107
-
108
- describe 'with custom pluggable parser' do
109
- before do
110
- class FakeJsonParser
111
- def serialize(value)
112
- return "42"
113
- end
114
-
115
- def parse(value)
116
- return 42
117
- end
118
- end
119
-
120
- @client.parser = FakeJsonParser.new
121
- end
122
-
123
- it 'should use the custom parser' do
124
- @client.parser.should be_instance_of(FakeJsonParser)
125
- end
126
-
127
- it_should_behave_like 'configurable user agent'
128
- end
129
103
  end
data/tasks/gem.rake CHANGED
@@ -1,4 +1,4 @@
1
- require 'rake/gempackagetask'
1
+ require 'rubygems/package_task'
2
2
 
3
3
  namespace :gem do
4
4
  GEM_SPEC = Gem::Specification.new do |s|
@@ -9,30 +9,32 @@ namespace :gem do
9
9
 
10
10
  s.name = PKG_NAME
11
11
  s.version = PKG_VERSION
12
+ s.author = PKG_AUTHOR
13
+ s.email = PKG_AUTHOR_EMAIL
12
14
  s.summary = PKG_SUMMARY
13
15
  s.description = PKG_DESCRIPTION
14
16
 
15
17
  s.files = PKG_FILES.to_a
16
18
  s.executables << 'google-api'
17
19
 
18
- s.has_rdoc = true
19
- s.extra_rdoc_files = %w( README )
20
- s.rdoc_options.concat ['--main', 'README']
20
+ s.extra_rdoc_files = %w( README.md )
21
+ s.rdoc_options.concat ['--main', 'README.md']
21
22
 
22
23
  # Dependencies used in the main library
23
24
  s.add_runtime_dependency('signet', '~> 0.2.2')
24
25
  s.add_runtime_dependency('addressable', '~> 2.2.2')
25
- s.add_runtime_dependency('httpadapter', '~> 1.0.0')
26
+ s.add_runtime_dependency('httpadapter', '~> 1.0.1')
27
+ s.add_runtime_dependency('autoparse', '~> 0.2.0')
26
28
  s.add_runtime_dependency('json', '>= 1.4.6')
27
29
  s.add_runtime_dependency('extlib', '>= 0.9.15')
28
30
 
29
31
  # Dependencies used in the CLI
30
- s.add_runtime_dependency('launchy', '>= 0.3.2')
32
+ s.add_runtime_dependency('launchy', '>= 2.0.0')
31
33
 
32
34
  # Dependencies used in the examples
33
- s.add_runtime_dependency('liquid', '>= 2.2.2')
35
+ s.add_development_dependency('sinatra', '>= 1.2.0')
34
36
 
35
- s.add_development_dependency('rake', '>= 0.7.3')
37
+ s.add_development_dependency('rake', '>= 0.9.0')
36
38
  s.add_development_dependency('rspec', '~> 1.2.9')
37
39
  s.add_development_dependency('rcov', '>= 0.9.9')
38
40
  s.add_development_dependency('diff-lcs', '>= 1.1.2')
@@ -42,7 +44,7 @@ namespace :gem do
42
44
  s.homepage = PKG_HOMEPAGE
43
45
  end
44
46
 
45
- Rake::GemPackageTask.new(GEM_SPEC) do |p|
47
+ Gem::PackageTask.new(GEM_SPEC) do |p|
46
48
  p.gem_spec = GEM_SPEC
47
49
  p.need_tar = true
48
50
  p.need_zip = true
@@ -53,6 +55,21 @@ namespace :gem do
53
55
  puts GEM_SPEC.to_ruby
54
56
  end
55
57
 
58
+ desc "Generates .gemspec file"
59
+ task :gemspec do
60
+ spec_string = GEM_SPEC.to_ruby
61
+
62
+ begin
63
+ Thread.new { eval("$SAFE = 3\n#{spec_string}", binding) }.join
64
+ rescue
65
+ abort "unsafe gemspec: #{$!}"
66
+ else
67
+ File.open("#{GEM_SPEC.name}.gemspec", 'w') do |file|
68
+ file.write spec_string
69
+ end
70
+ end
71
+ end
72
+
56
73
  desc 'Install the gem'
57
74
  task :install => ['clobber', 'gem:package'] do
58
75
  sh "#{SUDO} gem install --local pkg/#{GEM_SPEC.full_name}"
data/tasks/rdoc.rake CHANGED
@@ -1,14 +1,21 @@
1
- require 'rake/rdoctask'
1
+ require 'rubygems'
2
+ begin
3
+ # We prefer to use the RDoc gem over the site version.
4
+ gem 'rdoc'
5
+ rescue Gem::LoadError
6
+ end unless defined?(RDoc)
7
+
8
+ require 'rdoc/task'
2
9
 
3
10
  namespace :doc do
4
11
  desc 'Generate RDoc documentation'
5
- Rake::RDocTask.new do |rdoc|
12
+ RDoc::Task.new do |rdoc|
6
13
  rdoc.rdoc_dir = 'doc'
7
14
  rdoc.title = "#{PKG_NAME}-#{PKG_VERSION} Documentation"
8
- rdoc.options << '--line-numbers' << '--inline-source' <<
9
- '--accessor' << 'cattr_accessor=object' << '--charset' << 'utf-8'
15
+ rdoc.options << '--line-numbers' << 'cattr_accessor=object' <<
16
+ '--charset' << 'utf-8'
10
17
  rdoc.template = "#{ENV['template']}.rb" if ENV['template']
11
- rdoc.rdoc_files.include('README', 'CHANGELOG', 'LICENSE')
18
+ rdoc.rdoc_files.include('README.md', 'CHANGELOG', 'LICENSE')
12
19
  rdoc.rdoc_files.include('lib/**/*.rb')
13
20
  end
14
21
 
data/tasks/spec.rake CHANGED
@@ -17,11 +17,14 @@ namespace :spec do
17
17
  t.rcov = false
18
18
  end
19
19
  t.rcov_opts = [
20
+ '--exclude', 'lib\\/google\\/api_client\\/environment.rb',
21
+ '--exclude', 'lib\\/compat',
20
22
  '--exclude', 'spec',
21
23
  '--exclude', '\\.rvm\\/gems',
22
24
  '--exclude', '1\\.8\\/gems',
23
25
  '--exclude', '1\\.9\\/gems',
24
- '--exclude', '\\.rvm'
26
+ '--exclude', '\\.rvm',
27
+ '--exclude', '\\/Library\\/Ruby',
25
28
  ]
26
29
  end
27
30
 
data/tasks/wiki.rake ADDED
@@ -0,0 +1,41 @@
1
+ require 'google/api_client'
2
+
3
+ CACHE_PREFIX =
4
+ "http://www.gmodules.com/gadgets/proxy/container=default&debug=0&nocache=0/"
5
+
6
+ namespace :wiki do
7
+ desc 'Autogenerate wiki pages'
8
+ task :generate do
9
+ output = <<-WIKI
10
+ #summary The list of supported APIs
11
+
12
+ The Google API Client for Ruby is a small flexible client library for accessing
13
+ the following Google APIs.
14
+
15
+ WIKI
16
+ preferred_apis = {}
17
+ client = Google::APIClient.new
18
+ for api in client.discovered_apis
19
+ if !preferred_apis.has_key?(api.name)
20
+ preferred_apis[api.name] = api
21
+ elsif api.preferred
22
+ preferred_apis[api.name] = api
23
+ end
24
+ end
25
+ for api_name, api in preferred_apis
26
+ output += (
27
+ "||#{CACHE_PREFIX}#{api['icons']['x16']}||" +
28
+ "[#{api.documentation} #{api.title}]||" +
29
+ "#{api.description}||\n"
30
+ )
31
+ end
32
+ wiki_path = File.expand_path(
33
+ File.join(File.dirname(__FILE__), '../wiki/'))
34
+ Dir.mkdir(wiki_path) if !File.exist?(wiki_path)
35
+ File.open(File.join(wiki_path, 'SupportedAPIs.wiki'), 'w') do |file|
36
+ file.write(output)
37
+ end
38
+ end
39
+ end
40
+
41
+ # task 'clobber' => ['wiki:clobber_wiki']
data/tasks/yard.rake CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  yardoc.name = 'yard'
11
11
  yardoc.options = ['--verbose']
12
12
  yardoc.files = [
13
- 'lib/**/*.rb', 'ext/**/*.c', 'README', 'CHANGELOG', 'LICENSE'
13
+ 'lib/**/*.rb', 'ext/**/*.c', 'README.md', 'CHANGELOG', 'LICENSE'
14
14
  ]
15
15
  end
16
16
  end
metadata CHANGED
@@ -1,22 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-api-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
5
+ version: 0.3.0
11
6
  platform: ruby
12
- authors: []
13
-
7
+ authors:
8
+ - Bob Aman
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-05-12 00:00:00 -07:00
19
- default_executable:
13
+ date: 2011-11-16 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: signet
@@ -26,11 +20,6 @@ dependencies:
26
20
  requirements:
27
21
  - - ~>
28
22
  - !ruby/object:Gem::Version
29
- hash: 19
30
- segments:
31
- - 0
32
- - 2
33
- - 2
34
23
  version: 0.2.2
35
24
  type: :runtime
36
25
  version_requirements: *id001
@@ -42,11 +31,6 @@ dependencies:
42
31
  requirements:
43
32
  - - ~>
44
33
  - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 2
48
- - 2
49
- - 2
50
34
  version: 2.2.2
51
35
  type: :runtime
52
36
  version_requirements: *id002
@@ -58,158 +42,133 @@ dependencies:
58
42
  requirements:
59
43
  - - ~>
60
44
  - !ruby/object:Gem::Version
61
- hash: 23
62
- segments:
63
- - 1
64
- - 0
65
- - 0
66
- version: 1.0.0
45
+ version: 1.0.1
67
46
  type: :runtime
68
47
  version_requirements: *id003
69
48
  - !ruby/object:Gem::Dependency
70
- name: json
49
+ name: autoparse
71
50
  prerelease: false
72
51
  requirement: &id004 !ruby/object:Gem::Requirement
73
52
  none: false
74
53
  requirements:
75
- - - ">="
54
+ - - ~>
76
55
  - !ruby/object:Gem::Version
77
- hash: 11
78
- segments:
79
- - 1
80
- - 4
81
- - 6
82
- version: 1.4.6
56
+ version: 0.2.0
83
57
  type: :runtime
84
58
  version_requirements: *id004
85
59
  - !ruby/object:Gem::Dependency
86
- name: extlib
60
+ name: json
87
61
  prerelease: false
88
62
  requirement: &id005 !ruby/object:Gem::Requirement
89
63
  none: false
90
64
  requirements:
91
65
  - - ">="
92
66
  - !ruby/object:Gem::Version
93
- hash: 37
94
- segments:
95
- - 0
96
- - 9
97
- - 15
98
- version: 0.9.15
67
+ version: 1.4.6
99
68
  type: :runtime
100
69
  version_requirements: *id005
101
70
  - !ruby/object:Gem::Dependency
102
- name: launchy
71
+ name: extlib
103
72
  prerelease: false
104
73
  requirement: &id006 !ruby/object:Gem::Requirement
105
74
  none: false
106
75
  requirements:
107
76
  - - ">="
108
77
  - !ruby/object:Gem::Version
109
- hash: 23
110
- segments:
111
- - 0
112
- - 3
113
- - 2
114
- version: 0.3.2
78
+ version: 0.9.15
115
79
  type: :runtime
116
80
  version_requirements: *id006
117
81
  - !ruby/object:Gem::Dependency
118
- name: liquid
82
+ name: launchy
119
83
  prerelease: false
120
84
  requirement: &id007 !ruby/object:Gem::Requirement
121
85
  none: false
122
86
  requirements:
123
87
  - - ">="
124
88
  - !ruby/object:Gem::Version
125
- hash: 3
126
- segments:
127
- - 2
128
- - 2
129
- - 2
130
- version: 2.2.2
89
+ version: 2.0.0
131
90
  type: :runtime
132
91
  version_requirements: *id007
133
92
  - !ruby/object:Gem::Dependency
134
- name: rake
93
+ name: sinatra
135
94
  prerelease: false
136
95
  requirement: &id008 !ruby/object:Gem::Requirement
137
96
  none: false
138
97
  requirements:
139
98
  - - ">="
140
99
  - !ruby/object:Gem::Version
141
- hash: 5
142
- segments:
143
- - 0
144
- - 7
145
- - 3
146
- version: 0.7.3
100
+ version: 1.2.0
147
101
  type: :development
148
102
  version_requirements: *id008
149
103
  - !ruby/object:Gem::Dependency
150
- name: rspec
104
+ name: rake
151
105
  prerelease: false
152
106
  requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 0.9.0
112
+ type: :development
113
+ version_requirements: *id009
114
+ - !ruby/object:Gem::Dependency
115
+ name: rspec
116
+ prerelease: false
117
+ requirement: &id010 !ruby/object:Gem::Requirement
153
118
  none: false
154
119
  requirements:
155
120
  - - ~>
156
121
  - !ruby/object:Gem::Version
157
- hash: 13
158
- segments:
159
- - 1
160
- - 2
161
- - 9
162
122
  version: 1.2.9
163
123
  type: :development
164
- version_requirements: *id009
124
+ version_requirements: *id010
165
125
  - !ruby/object:Gem::Dependency
166
126
  name: rcov
167
127
  prerelease: false
168
- requirement: &id010 !ruby/object:Gem::Requirement
128
+ requirement: &id011 !ruby/object:Gem::Requirement
169
129
  none: false
170
130
  requirements:
171
131
  - - ">="
172
132
  - !ruby/object:Gem::Version
173
- hash: 41
174
- segments:
175
- - 0
176
- - 9
177
- - 9
178
133
  version: 0.9.9
179
134
  type: :development
180
- version_requirements: *id010
135
+ version_requirements: *id011
181
136
  - !ruby/object:Gem::Dependency
182
137
  name: diff-lcs
183
138
  prerelease: false
184
- requirement: &id011 !ruby/object:Gem::Requirement
139
+ requirement: &id012 !ruby/object:Gem::Requirement
185
140
  none: false
186
141
  requirements:
187
142
  - - ">="
188
143
  - !ruby/object:Gem::Version
189
- hash: 23
190
- segments:
191
- - 1
192
- - 1
193
- - 2
194
144
  version: 1.1.2
195
145
  type: :development
196
- version_requirements: *id011
146
+ version_requirements: *id012
197
147
  description: |
198
148
  The Google API Ruby Client makes it trivial to discover and access supported
199
149
  APIs.
200
150
 
201
- email:
151
+ email: bobaman@google.com
202
152
  executables:
203
153
  - google-api
204
154
  extensions: []
205
155
 
206
156
  extra_rdoc_files:
207
- - README
157
+ - README.md
208
158
  files:
159
+ - lib/google/api_client/discovery/api.rb
160
+ - lib/google/api_client/discovery/method.rb
161
+ - lib/google/api_client/discovery/resource.rb
162
+ - lib/google/api_client/discovery/schema.rb
209
163
  - lib/google/api_client/discovery.rb
210
164
  - lib/google/api_client/environment.rb
211
165
  - lib/google/api_client/errors.rb
166
+ - lib/google/api_client/parser.rb
167
+ - lib/google/api_client/parsers/json/error_parser.rb
168
+ - lib/google/api_client/parsers/json/pagination.rb
212
169
  - lib/google/api_client/parsers/json_parser.rb
170
+ - lib/google/api_client/reference.rb
171
+ - lib/google/api_client/result.rb
213
172
  - lib/google/api_client/version.rb
214
173
  - lib/google/api_client.rb
215
174
  - lib/google/inflection.rb
@@ -224,20 +183,20 @@ files:
224
183
  - tasks/metrics.rake
225
184
  - tasks/rdoc.rake
226
185
  - tasks/spec.rake
186
+ - tasks/wiki.rake
227
187
  - tasks/yard.rake
228
188
  - CHANGELOG
229
189
  - LICENSE
230
190
  - Rakefile
231
- - README
191
+ - README.md
232
192
  - bin/google-api
233
- has_rdoc: true
234
193
  homepage: http://code.google.com/p/google-api-ruby-client/
235
194
  licenses: []
236
195
 
237
196
  post_install_message:
238
197
  rdoc_options:
239
198
  - --main
240
- - README
199
+ - README.md
241
200
  require_paths:
242
201
  - lib
243
202
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -245,23 +204,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
204
  requirements:
246
205
  - - ">="
247
206
  - !ruby/object:Gem::Version
248
- hash: 3
249
- segments:
250
- - 0
251
207
  version: "0"
252
208
  required_rubygems_version: !ruby/object:Gem::Requirement
253
209
  none: false
254
210
  requirements:
255
211
  - - ">="
256
212
  - !ruby/object:Gem::Version
257
- hash: 3
258
- segments:
259
- - 0
260
213
  version: "0"
261
214
  requirements: []
262
215
 
263
216
  rubyforge_project:
264
- rubygems_version: 1.4.1
217
+ rubygems_version: 1.8.11
265
218
  signing_key:
266
219
  specification_version: 3
267
220
  summary: Package Summary