google_apps_oauth2 0.1

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.
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoogleAppsOauth2::Atom::Feed do
4
+ let (:xml) { File.read('spec/fixture_xml/users_feed.xml') }
5
+ let (:next_page) { 'https://apps-apis.google.com/a/feeds/cnm.edu/user/2.0?startUsername=aadams37' }
6
+ let (:feed) { GoogleAppsOauth2::Atom::Feed.new(xml) }
7
+ let (:content_array) { ['<apps:login userId="Mom"/>', '<apps:quota value="80"/>', '<id/>', '<atom:category/>'] }
8
+
9
+ describe "#new" do
10
+ it "Parses the given xml" do
11
+ feed.doc.should be_a LibXML::XML::Document
12
+ end
13
+
14
+ it "Populates @items with Atom objects of the proper type" do
15
+ feed.items.first.should be_a GoogleAppsOauth2::Atom::User
16
+ end
17
+ end
18
+
19
+ describe "#next_page" do
20
+ it "Sets the url for the next page in the feed" do
21
+ feed.next_page.should == next_page
22
+ end
23
+ end
24
+
25
+ describe "#entries_from" do
26
+ it "Builds an array of Atom objects" do # We have a bad regex somewhere, User doesn't work as an argument
27
+ results = feed.entries_from document: feed.doc, type: 'user', entry_tag: 'entry'
28
+
29
+ results.first.should be_a GoogleAppsOauth2::Atom::User
30
+ end
31
+ end
32
+
33
+ describe "#add_category" do
34
+ it "Adds an atom:category node to the front of the content_array" do
35
+ content = feed.add_category(content_array).join("\n")
36
+
37
+ content.should include '<atom:category'
38
+ content.should include '#user'
39
+ end
40
+ end
41
+
42
+ describe "#entry_wrap" do
43
+ it "Wraps the given content in an apps:entry element" do
44
+ entry = feed.entry_wrap(["bob"]).join("\n")
45
+
46
+ entry.should include "<atom:entry xmlns:atom"
47
+ entry.should include "bob"
48
+ entry.should include "</atom:entry>"
49
+ end
50
+ end
51
+
52
+ describe "#node_to_ary" do
53
+ it "Returns the content of a node as an array" do
54
+ content = feed.node_to_ary(entry_node)
55
+
56
+ content.should be_an Array
57
+ end
58
+ end
59
+
60
+ describe "#grab_elements" do
61
+ it "Grabs all elements from the content array matching the filter" do
62
+ matches = feed.grab_elements(content_array, 'apps:')
63
+
64
+ matches.each do |match|
65
+ match.should include 'apps:'
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def entry_node
72
+ entry = LibXML::XML::Node.new 'entry'
73
+
74
+ entry << LibXML::XML::Node.new('uncle')
75
+ entry << LibXML::XML::Node.new('aunt')
76
+
77
+ entry
78
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoogleAppsOauth2::Atom::Node do
4
+ let (:node_class) { class TestNode < BasicObject; include ::GoogleAppsOauth2::Atom::Node; end }
5
+ let (:node) { node_class.new }
6
+ let (:document) { LibXML::XML::Document.file('spec/fixture_xml/users_feed.xml') }
7
+
8
+ describe "#create_node" do
9
+ it "Creates a LibXML::XML::Node with the given attributes" do
10
+ sample = node.create_node type: 'apps:nickname', attrs: [['name', 'Bob']]
11
+
12
+ sample.to_s.should include 'apps:nickname name="Bob"'
13
+ end
14
+
15
+ it "Creates a Node with multiple attributes" do
16
+ sample = node.create_node type: 'apps:nickname', attrs: [['name', 'Lou'], ['type', 'fake']]
17
+
18
+ sample.to_s.should include 'apps:nickname name="Lou" type="fake"'
19
+ end
20
+
21
+ it "Creates a LibXML::XML::Node without attributes if none are given" do
22
+ (node.create_node type: 'apps:nickname').to_s.should include 'apps:nickname'
23
+ end
24
+ end
25
+
26
+ describe "#add_attributes" do
27
+ it "Adds the specified attributes to the given node" do
28
+ test = LibXML::XML::Node.new 'apps:test'
29
+ node.add_attributes(test, [['name', 'frank'], ['title', 'captain']])
30
+
31
+ test.to_s.should include 'name="frank" title="captain"'
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoogleAppsOauth2::Atom::User do
4
+ let (:gapp) { GoogleAppsOauth2::Atom::User.new(xml) }
5
+ let (:user) { ["test_account", "Test", "Account", "db64e604690686663821888f20373a3941ed7e95", 2048] }
6
+ let (:xml) { File.read('spec/fixture_xml/user.xml') }
7
+ let (:default_password) { 'default' }
8
+
9
+ describe '#new' do
10
+ it "creates an xml document matching the given argument" do
11
+ usr = GoogleAppsOauth2::Atom.user xml
12
+
13
+ usr.doc.to_s.should include xml
14
+ end
15
+ end
16
+
17
+ describe "#find_values" do
18
+ it "Populates instance variables with values from @doc" do
19
+ user = GoogleAppsOauth2::Atom::User.new xml
20
+
21
+ user.login.should == 'lholcomb2'
22
+ user.suspended.should == false
23
+ user.first_name.should == 'Lawrence'
24
+ user.last_name.should == 'Holcomb'
25
+ end
26
+ end
27
+
28
+ describe "#check_value" do
29
+ it "Returns true if the value is 'true'" do
30
+ gapp.send(:check_value, 'true').should == true
31
+ end
32
+
33
+ it "Returns flase if the value is 'false'" do
34
+ gapp.send(:check_value, 'false').should == false
35
+ end
36
+
37
+ it "Returns the origional object if not == 'true' or 'false'" do
38
+ gapp.send(:check_value, 'bob').should == 'bob'
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ module GoogleAppsOauth2
4
+ module Parsers
5
+ describe FeedParser do
6
+ describe '#call' do
7
+ it "returns an array of users" do
8
+ body = File.read('spec/fixture_xml/users_feed.xml')
9
+ users = FeedParser.call(body, :atom)
10
+
11
+ users.first.class.should == GoogleAppsOauth2::Atom::User
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoogleAppsOauth2::Transport do
4
+ let(:client_secret) { 'sfdfsd087sdf' }
5
+ let(:client_id) { 'blahblahid' }
6
+ let(:transporter) do
7
+ GoogleAppsOauth2::Transport.new(
8
+ domain: 'cnm.edu',
9
+ token: 'some-token',
10
+ refresh_token: 'refresh-token',
11
+ client_id: client_id,
12
+ client_secret: client_secret
13
+ ) do |new_token|
14
+ @current_token = new_token
15
+ end
16
+ end
17
+
18
+ describe "#get_users" do
19
+ it "Builds a GET request for the user endpoint" do
20
+ stub = stub_users_ok(token: 'some-token')
21
+
22
+ transporter.get_users(start: 'znelson1', limit: 2)
23
+ stub.should have_been_requested
24
+ end
25
+
26
+ context 'token has expired' do
27
+ it "refreshes the token when the old one expires" do
28
+ stub_users_expired_token(token: 'some-token')
29
+ stub_refresh_token()
30
+ stub_users_ok(token: 'some-new-token')
31
+
32
+ transporter.get_users(start: 'znelson1', limit: 2).code.should == 200
33
+ end
34
+
35
+ it "calls the block with the new token as a param" do
36
+ @current_token = "old-and-expired"
37
+ stub_users_expired_token(token: 'some-token')
38
+ stub_refresh_token()
39
+ stub_users_ok(token: 'some-new-token')
40
+
41
+ transporter.get_users(start: 'znelson1', limit: 2).code.should == 200
42
+ @current_token.should == 'some-new-token'
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ require 'google_apps_oauth2'
2
+ require 'webmock/rspec'
3
+
4
+ # Requires supporting ruby files with custom matchers and macros, etc,
5
+ # in spec/support/ and its subdirectories.
6
+ Dir[File.expand_path(File.dirname(__FILE__) + '/support/**/*.rb')].each { |f| require f }
7
+
8
+ #WebMock.allow_net_connect!
9
+ WebMock.disable_net_connect!
10
+
11
+ RSpec.configure do |config|
12
+ #config.include FactoryGirl::Syntax::Methods
13
+ #config.order = "random"
14
+ end
15
+
@@ -0,0 +1,16 @@
1
+ def stub_users_expired_token(options = {})
2
+ stub_request(:get, "https://apps-apis.google.com/a/feeds/cnm.edu/user/2.0?startUsername=znelson1").
3
+ with(:headers => {'Authorization' => "OAuth #{options[:token]}", 'Content-Type' => 'application/atom+xml'}).
4
+ to_return(:status => 401, :body => File.read('spec/fixtures/invalid_token.html'))
5
+ end
6
+
7
+ def stub_refresh_token
8
+ stub_request(:post, "https://accounts.google.com/o/oauth2/token").
9
+ to_return(:status => 200, :body => File.read('spec/fixtures/refreshed_token_response.json'))
10
+ end
11
+
12
+ def stub_users_ok(options = {})
13
+ stub_request(:get, "https://apps-apis.google.com/a/feeds/cnm.edu/user/2.0?startUsername=znelson1").
14
+ with(:headers => {'Authorization' => "OAuth #{options[:token]}", 'Content-Type' => 'application/atom+xml'}).
15
+ to_return(:status => 200, :body => File.read('spec/fixtures/users_feed.xml'))
16
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_apps_oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Will Read
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libxml-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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: webmock
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
+ description: Library for interfacing with Google Apps Domain and Application APIs
84
+ via OAuth2
85
+ email:
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - google_apps_oauth2.gemspec
97
+ - lib/google_apps_oauth2.rb
98
+ - lib/google_apps_oauth2/atom/atom.rb
99
+ - lib/google_apps_oauth2/atom/document.rb
100
+ - lib/google_apps_oauth2/atom/feed.rb
101
+ - lib/google_apps_oauth2/atom/node.rb
102
+ - lib/google_apps_oauth2/atom/user.rb
103
+ - lib/google_apps_oauth2/parsers/feed_parser.rb
104
+ - lib/google_apps_oauth2/transport.rb
105
+ - spec/fixtures/invalid_token.html
106
+ - spec/fixtures/refreshed_token_response.json
107
+ - spec/fixtures/user.xml
108
+ - spec/fixtures/users_feed.xml
109
+ - spec/google_apps_oauth2/atom/document_spec.rb
110
+ - spec/google_apps_oauth2/atom/feed_spec.rb
111
+ - spec/google_apps_oauth2/atom/node_spec.rb
112
+ - spec/google_apps_oauth2/atom/user_spec.rb
113
+ - spec/google_apps_oauth2/parsers/feed_parser_spec.rb
114
+ - spec/google_apps_oauth2/transport_spec.rb
115
+ - spec/spec_helper.rb
116
+ - spec/support/web_stubs.rb
117
+ homepage: https://github.com/TildeWill/google_apps
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.0.0
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Google Apps APIs using OAuth2
141
+ test_files:
142
+ - spec/fixtures/invalid_token.html
143
+ - spec/fixtures/refreshed_token_response.json
144
+ - spec/fixtures/user.xml
145
+ - spec/fixtures/users_feed.xml
146
+ - spec/google_apps_oauth2/atom/document_spec.rb
147
+ - spec/google_apps_oauth2/atom/feed_spec.rb
148
+ - spec/google_apps_oauth2/atom/node_spec.rb
149
+ - spec/google_apps_oauth2/atom/user_spec.rb
150
+ - spec/google_apps_oauth2/parsers/feed_parser_spec.rb
151
+ - spec/google_apps_oauth2/transport_spec.rb
152
+ - spec/spec_helper.rb
153
+ - spec/support/web_stubs.rb