google_contacts_api 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{google_contacts_api}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
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 = %q{2011-07-21}
12
+ s.date = %q{2011-08-12}
13
13
  s.description = %q{Lets you read from the Google Contacts API. Posting to come later. Tests to come later.}
14
14
  s.email = %q{ayliang@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -1,6 +1,8 @@
1
1
  require 'active_support/core_ext'
2
2
 
3
3
  module GoogleContactsApi
4
+ class UnauthorizedError < StandardError; end
5
+
4
6
  class Api
5
7
  # keep separate in case of new auth method
6
8
  BASE_URL = "https://www.google.com/m8/feeds/"
@@ -15,9 +17,14 @@ module GoogleContactsApi
15
17
  # For get, post, put, delete, always use JSON, it's simpler
16
18
  # and lets us use Hashie::Mash. Note that in the JSON conversion from XML,
17
19
  # ":" is replaced with $, element content is keyed with $t
20
+ # Raise UnauthorizedError if not authorized.
18
21
  def get(link, params = {}, headers = {})
19
22
  params["alt"] = "json"
20
- @oauth.get("#{BASE_URL}#{link}?#{params.to_query}", headers)
23
+ result = @oauth.get("#{BASE_URL}#{link}?#{params.to_query}", headers)
24
+ # For the full HTML we're matching against, see the spec
25
+ # TODO: This could be pretty fragile.
26
+ raise UnauthorizedError if result.include?("Token invalid - Invalid AuthSub token.") && result.include?("Error 401")
27
+ result
21
28
  end
22
29
 
23
30
  # Post request to specified link, with query params
@@ -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.5"
12
+ VERSION = "0.2.6"
13
13
  end
@@ -20,6 +20,27 @@ describe "GoogleContactsApi" do
20
20
  pending "should perform a post request using oauth"
21
21
  pending "should perform a put request using oauth"
22
22
  pending "should perform a delete request using oauth"
23
+ # Not sure how to test, you'd need a revoked token.
24
+ it "should raise UnauthorizedError if token or request is invalid" do
25
+ 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!
38
+ oauth.stub(:get).and_return(error_html)
39
+ api = GoogleContactsApi::Api.new(oauth)
40
+ lambda { api.get("any url",
41
+ {"param" => "param"},
42
+ {"header" => "header"}) }.should raise_error(GoogleContactsApi::UnauthorizedError)
43
+ end
23
44
  end
24
45
 
25
46
  describe "User" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: google_contacts_api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.5
5
+ version: 0.2.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alvin Liang
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-21 00:00:00 -04:00
13
+ date: 2011-08-12 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -157,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
159
159
  - !ruby/object:Gem::Version
160
- hash: 920346091884577731
160
+ hash: -4187729260507670250
161
161
  segments:
162
162
  - 0
163
163
  version: "0"