google_contacts_api 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -4,7 +4,11 @@ An unofficial Google Contacts API for ruby. Might not be stable (but probably is
4
4
 
5
5
  ## Do the tests pass?
6
6
 
7
- [![Build Status](https://travis-ci.org/[YOUR_GITHUB_USERNAME]/[YOUR_PROJECT_NAME].png)](https://travis-ci.org/[YOUR_GITHUB_USERNAME]/[YOUR_PROJECT_NAME])
7
+ [![Build Status](https://travis-ci.org/aliang/google_contacts_api.png)](https://travis-ci.org/aliang/google_contacts_api)
8
+
9
+ ## Upgrading
10
+
11
+ Right now upgrading should just work, barring any bugs in my implementation. In the next major version I will probably drop (or at least stop maintaining) support for OAuth::AccessToken objects and depend directly on the [oauth2](https://github.com/intridea/oauth2) gem.
8
12
 
9
13
  ## Usage
10
14
 
@@ -59,6 +63,6 @@ by jeweler).
59
63
 
60
64
  ## Copyright
61
65
 
62
- Copyright (c) 2011 Alvin Liang. See LICENSE.txt for further details.
66
+ Copyright (c) 2011-13 Alvin Liang. See LICENSE.txt for further details.
63
67
 
64
68
  Some code based on a few bugfixes in lfittl and fraudpointer forks.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "google_contacts_api"
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alvin Liang"]
12
- s.date = "2013-01-11"
12
+ s.date = "2013-01-15"
13
13
  s.description = "Lets you read from the Google Contacts API. Posting to come later. Tests to come later."
14
14
  s.email = "ayliang@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
37
37
  "lib/google_contacts_api/user.rb",
38
38
  "spec/contact_set.json",
39
39
  "spec/empty_contact_set.json",
40
+ "spec/errors/auth_sub_401.html",
40
41
  "spec/google_contacts_api_spec.rb",
41
42
  "spec/group_set.json",
42
43
  "spec/spec_helper.rb"
@@ -21,11 +21,16 @@ module GoogleContactsApi
21
21
  # Raise UnauthorizedError if not authorized.
22
22
  def get(link, params = {}, headers = {})
23
23
  params["alt"] = "json"
24
- result = @oauth.get("#{BASE_URL}#{link}?#{params.to_query}", headers)
25
- # For the full HTML we're matching against, see the spec
26
- # TODO: This could be pretty fragile.
24
+ begin
25
+ result = @oauth.get("#{BASE_URL}#{link}?#{params.to_query}", headers)
26
+ rescue => e
27
+ # TODO: OAuth 2.0 will raise a real error
28
+ raise UnauthorizedError if defined?(e.response) && self.class.parse_response_code(e.response) == 401
29
+ raise e
30
+ end
31
+
32
+ # OAuth 1.0 uses Net::HTTP internally
27
33
  raise UnauthorizedError if result.is_a?(Net::HTTPUnauthorized)
28
- # raise UnauthorizedError if result.include?("Token invalid - Invalid AuthSub token.") && result.include?("Error 401")
29
34
  result
30
35
  end
31
36
 
@@ -9,5 +9,5 @@ require 'google_contacts_api/group'
9
9
  require 'google_contacts_api/contact'
10
10
 
11
11
  module GoogleContactsApi
12
- VERSION = "0.2.7"
12
+ VERSION = "0.3.3"
13
13
  end
File without changes
@@ -1,5 +1,13 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
+ class MockOAuth2Error < StandardError
4
+ attr_accessor :response
5
+
6
+ def initialize(response)
7
+ @response = response
8
+ end
9
+ end
10
+
3
11
  describe "GoogleContactsApi" do
4
12
  describe "Api" do
5
13
  before(:each) do
@@ -21,20 +29,9 @@ describe "GoogleContactsApi" do
21
29
  pending "should perform a put request using oauth"
22
30
  pending "should perform a delete request using oauth"
23
31
  # Not sure how to test, you'd need a revoked token.
24
- it "should raise UnauthorizedError if token or request is invalid" do
32
+ it "should raise UnauthorizedError if OAuth 1.0 returns unauthorized" do
25
33
  oauth = double("oauth")
26
- error_html = <<-ERROR_HTML
27
- <HTML>
28
- <HEAD>
29
- <TITLE>Token invalid - Invalid AuthSub token.</TITLE>
30
- </HEAD>
31
- <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
32
- <H1>Token invalid - Invalid AuthSub token.</H1>
33
- <H2>Error 401</H2>
34
- </BODY>
35
- </HTML>
36
- ERROR_HTML
37
- error_html.strip!
34
+ error_html = load_file(File.join('errors', 'auth_sub_401.html'))
38
35
  oauth.stub(:get).and_return(Net::HTTPUnauthorized.new("1.1", 401, error_html))
39
36
  api = GoogleContactsApi::Api.new(oauth)
40
37
  lambda { api.get("any url",
@@ -42,6 +39,16 @@ describe "GoogleContactsApi" do
42
39
  {"header" => "header"}) }.should raise_error(GoogleContactsApi::UnauthorizedError)
43
40
  end
44
41
 
42
+ it "should raise UnauthorizedError if OAuth 2.0 returns unauthorized" do
43
+ oauth = double("oauth2")
44
+ oauth2_response = Struct.new(:status)
45
+ oauth.stub(:get).and_raise(MockOAuth2Error.new(oauth2_response.new(401)))
46
+ api = GoogleContactsApi::Api.new(oauth)
47
+ lambda { api.get("any url",
48
+ {"param" => "param"},
49
+ {"header" => "header"}) }.should raise_error(GoogleContactsApi::UnauthorizedError)
50
+ end
51
+
45
52
  describe "parsing response code" do
46
53
  before(:all) do
47
54
  @Oauth = Struct.new(:code)
@@ -52,8 +59,7 @@ describe "GoogleContactsApi" do
52
59
  end
53
60
 
54
61
  it "should parse something that looks like an oauth2 gem response" do
55
- Resp = Struct.new(:status)
56
- GoogleContactsApi::Api.parse_response_code(@Oauth2.new("401")).should == 401
62
+ GoogleContactsApi::Api.parse_response_code(@Oauth2.new(401)).should == 401
57
63
  end
58
64
  end
59
65
  end
data/spec/spec_helper.rb CHANGED
@@ -16,7 +16,7 @@ RSpec.configure do |config|
16
16
  config.mock_framework = :rspec
17
17
  end
18
18
 
19
- def contact_set_json_from_file(filename)
19
+ def load_file(filename)
20
20
  f = File.open(File.join(File.dirname(__FILE__), filename))
21
21
  json = f.read
22
22
  f.close
@@ -24,15 +24,15 @@ def contact_set_json_from_file(filename)
24
24
  end
25
25
 
26
26
  def contact_set_json
27
- contact_set_json_from_file("contact_set.json")
27
+ load_file("contact_set.json")
28
28
  end
29
29
 
30
30
  def group_set_json
31
- contact_set_json_from_file("group_set.json")
31
+ load_file("group_set.json")
32
32
  end
33
33
 
34
34
  def empty_contact_set_json
35
- contact_set_json_from_file("empty_contact_set.json")
35
+ load_file("empty_contact_set.json")
36
36
  end
37
37
 
38
38
  def contact_json_hash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_contacts_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -216,6 +216,7 @@ files:
216
216
  - lib/google_contacts_api/user.rb
217
217
  - spec/contact_set.json
218
218
  - spec/empty_contact_set.json
219
+ - spec/errors/auth_sub_401.html
219
220
  - spec/google_contacts_api_spec.rb
220
221
  - spec/group_set.json
221
222
  - spec/spec_helper.rb
@@ -234,7 +235,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
235
  version: '0'
235
236
  segments:
236
237
  - 0
237
- hash: 3165396795363090061
238
+ hash: -4068781390085911167
238
239
  required_rubygems_version: !ruby/object:Gem::Requirement
239
240
  none: false
240
241
  requirements: