gprov 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,19 @@
1
1
  Ruby-GProv
2
2
  ==========
3
3
 
4
+ Synopsis
5
+ --------
6
+
7
+ This is a ruby implementation of the Ruby implementation of the [Google Provisioning API][api].
8
+
4
9
  Description
5
10
  -----------
6
11
 
7
- This is a ruby implementation of the Ruby implementation of the [Google
8
- Provisioning API][api]. It's designed to provide an object oriented approach to
9
- the API instead of the weird procedural approach that's the straight
10
- implementation. By and large it's modelled in the manner of CRUD.
12
+ The specification of the Google Provisioning API is primarily procedural in
13
+ nature, despite that all the languages that Google provides bindings for are
14
+ object oriented. This implementation attempts to provide a more natural
15
+ interface to that API. Where applicable, objects present a CRUD-like set of
16
+ methods to perform operations on the underlying system.
11
17
 
12
18
  [api]: http://code.google.com/googleapps/domain/gdata_provisioning_api_v2.0_reference.html "Google Provisioning API v2.0"
13
19
 
@@ -1,4 +1,4 @@
1
- # = gprov/connection.rb: common interface for the google apps API
1
+ # = GProv::Connection: common interface for the google apps API
2
2
  #
3
3
  # == Overview
4
4
  #
@@ -52,8 +52,15 @@ module GProv
52
52
  if path.nil?
53
53
  raise "#{self.class}##{verb} requires a non-nil path"
54
54
  end
55
- options = *args
56
- options ||= {}
55
+
56
+ # If extra headers were passed in, explode the containing array. Else,
57
+ # create a new empty hash. When that's done, merge the Google API
58
+ # headers.
59
+ case args.length
60
+ when 0 then options = {}
61
+ when 1 then options = args.pop
62
+ else options = *args
63
+ end
57
64
  options.merge! default_headers
58
65
 
59
66
  # Interpolate the :domain substring into a url to allow for the domain
@@ -61,8 +68,8 @@ module GProv
61
68
  path.gsub!(":domain", @domain)
62
69
 
63
70
  if options[:noop] or @options[:noop]
64
- $stderr.puts "Would have attempted the following call"
65
- $stderr.puts "#{verb} #{path} #{options.inspect}"
71
+ warn "Would have attempted the following call"
72
+ warn "#{verb} #{path} #{options.inspect}"
66
73
  else
67
74
  # Return the request to the calling class so that the caller can
68
75
  # determine the outcome of the request.
@@ -1,3 +1,3 @@
1
1
  module GProv
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe GProv::Auth::ClientLogin do
4
4
 
5
- before :each do
6
- @klass = GProv::Auth::ClientLogin
7
- @instance = @klass.new('test', 'password', 'service')
8
- @dummy_form = {:body => {
5
+ let(:klass) { GProv::Auth::ClientLogin }
6
+
7
+ let(:dummy_form) do
8
+ {:body => {
9
9
  "accountType" => "HOSTED",
10
10
  "Email" => "test",
11
11
  "Passwd" => "password",
@@ -13,35 +13,36 @@ describe GProv::Auth::ClientLogin do
13
13
  }}
14
14
  end
15
15
 
16
+ subject { GProv::Auth::ClientLogin.new('test', 'password', 'service') }
17
+
16
18
  it "should use the google ClientLogin uri" do
17
- GProv::Auth::ClientLogin.base_uri.should == "https://www.google.com/accounts/ClientLogin"
19
+ klass.base_uri.should == "https://www.google.com/accounts/ClientLogin"
18
20
  end
19
21
 
20
- it "should have a token method" do
21
- @instance.respond_to?(:token).should == true
22
- end
22
+ it { should respond_to :token }
23
23
 
24
- it "should post valid form data to the uri specified base_uri" do
25
- stub_response = stub :response
26
- stub_response.stubs(:code).returns 200
27
- stub_response.stubs(:body).returns "Auth=dummy\n"
28
- @klass.expects(:post).with('', @dummy_form).returns stub_response
29
- @instance.token
30
- end
24
+ describe "when posting" do
25
+ let(:response) { stub :response }
31
26
 
32
- it "should return nil if authorization failed" do
33
- stub_response = stub :response
34
- stub_response.stubs(:code).returns 403
35
- @klass.expects(:post).with('', @dummy_form).returns stub_response
36
- @instance.token.should be_nil
37
- end
27
+ before :each do
28
+ klass.stubs(:post).with('', dummy_form).returns response
29
+ end
38
30
 
39
- it "should return the token if authorization succeeded" do
40
- stub_response = stub :response
41
- stub_response.stubs(:code).returns 200
42
- stub_response.stubs(:body).returns "Auth=dummy\n"
43
- @klass.expects(:post).with('', @dummy_form).returns stub_response
44
- @instance.token.should == "dummy"
45
- end
31
+ describe "invalid credentials" do
32
+ before do
33
+ response.stubs(:code).returns 403
34
+ end
35
+
36
+ its(:token) { should be_nil }
37
+ end
46
38
 
39
+ describe "valid credentials" do
40
+ before do
41
+ response.stubs(:code).returns 200
42
+ response.stubs(:body).returns "Auth=dummy\n"
43
+ end
44
+
45
+ its(:token) { should == "dummy" }
46
+ end
47
+ end
47
48
  end
@@ -2,58 +2,57 @@ require 'spec_helper'
2
2
 
3
3
  describe GProv::Connection do
4
4
 
5
- before :each do
6
- @klass = GProv::Connection
7
- @instance = @klass.new("domain", "token")
5
+ let(:klass) { GProv::Connection }
8
6
 
9
- @expected_options = {:headers => {
7
+ subject { GProv::Connection.new("domain", "token") }
8
+
9
+ let(:expected_options) do
10
+ {:headers => {
10
11
  'Authorization' => "GoogleLogin auth=token",
11
12
  'Content-Type' => 'application/atom+xml',
12
13
  }}
13
14
  end
14
15
 
15
16
  it "should use to google apps API url as the base uri" do
16
- @klass.base_uri.should == "https://apps-apis.google.com/a/feeds"
17
+ klass.base_uri.should == "https://apps-apis.google.com/a/feeds"
17
18
  end
18
19
 
19
- it "should have a domain accessor" do
20
- @instance.respond_to?(:domain).should == true
21
- end
20
+ it { should respond_to :domain }
22
21
 
23
22
  it "should expose the default headers" do
24
- @instance.default_headers.should == @expected_options
23
+ subject.default_headers.should == expected_options
25
24
  end
26
25
 
27
26
 
28
27
  describe "http instance method" do
29
28
  [:put, :get, :post, :delete].each do |verb|
30
- describe %Q{"#{verb}"} do
29
+
30
+ it { should respond_to verb }
31
+
32
+ describe "##{verb}" do
31
33
  before do
32
- xml = %Q{<?xml version="1.0" encoding="UTF-8"?>\n<test xml="pointy"/>}
34
+ xml = %Q{<?xml version="1.0" encoding="UTF-8"?>\n<test xml="pointy" />}
33
35
  @stub_request = mock
34
36
  @stub_request.stubs(:code).returns 200
35
37
  @stub_request.stubs(:success?).returns true
36
38
  @stub_request.stubs(:class).returns HTTParty::Response
37
39
  end
38
40
 
39
- it "should be an instance method" do
40
- @instance.respond_to?(verb).should == true
41
- end
42
41
 
43
42
  it "should be forwarded to the class" do
44
- @klass.expects(verb).returns @stub_request
45
- @instance.send(verb, '')
43
+ klass.expects(verb).returns @stub_request
44
+ subject.send(verb, '')
46
45
  end
47
46
 
48
47
  it "should return the http response" do
49
- @klass.expects(verb).returns @stub_request
50
- output = @instance.send(verb, "/url")
48
+ klass.expects(verb).returns @stub_request
49
+ output = subject.send(verb, "/url")
51
50
  output.class.should == HTTParty::Response
52
51
  end
53
52
 
54
53
  it "should interpolate the :domain substring" do
55
- @klass.expects(verb).with("/domain", @expected_options).returns @stub_request
56
- @instance.send(verb, "/:domain")
54
+ klass.expects(verb).with("/domain", expected_options).returns @stub_request
55
+ subject.send(verb, "/:domain")
57
56
  end
58
57
  end
59
58
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'fakeentry'
3
+
4
+ describe GProv::Provision::EntryBase::ClassMethods do
5
+
6
+ subject { FakeEntry }
7
+
8
+ [:xmlattr, :xml_to_hash, :attributes].each do |method|
9
+ it { should respond_to method }
10
+ end
11
+
12
+ end
@@ -1,39 +1,11 @@
1
1
  require 'spec_helper'
2
+ require 'fakeentry'
2
3
 
3
- class FakeEntry < GProv::Provision::EntryBase
4
-
5
- xml_attr_accessor :test, :xpath => "/foo/bar/text()"
6
- xml_attr_accessor :test_transform, :xpath => "/foo/bar/text()", :transform => lambda {|x| x.upcase}
7
- end
4
+ # Tests are against the fakeentry fixture
8
5
 
9
6
  describe GProv::Provision::EntryBase do
10
7
 
11
- before do
12
- @klass = GProv::Provision::EntryBase
13
- @test_klass = FakeEntry
14
- @instance = @test_klass.new
15
- end
16
-
17
- describe GProv::Provision::EntryBase::ClassMethods do
18
-
19
- [:xml_attr_accessor, :xml_to_hash, :attributes].each do |method|
20
- it "method #{method} should be a class method" do
21
- FakeEntry.respond_to?(method).should be_true
22
- end
23
- end
24
-
25
- it "xml_attr_accessor should receive a symbol and hash of attributes" do
26
- @test_klass.attributes[:test].should == {:xpath => "/foo/bar/text()"}
27
- end
28
-
29
- describe "xml_to_hash" do
30
- end
31
- end
32
-
33
-
34
8
  [:status, :connection].each do |method|
35
- it "method #{method} should be an instance method" do
36
- @instance.respond_to?(method).should be_true
37
- end
9
+ it { should respond_to method }
38
10
  end
39
11
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe GProv::Provision::User do
4
+
5
+ [:create!, :update!, :delete].each do |method|
6
+ it { should respond_to method }
7
+ end
8
+ end
9
+
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe GProv::Provision::User do
4
+
5
+ [:create!, :update!, :delete].each do |method|
6
+ it { should respond_to method }
7
+ end
8
+ end
9
+
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe GProv::Provision::User do
4
+
5
+ [:create!, :update!, :delete].each do |method|
6
+ it { should respond_to method }
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ require 'gprov'
2
+
3
+ class FakeEntry < GProv::Provision::EntryBase
4
+
5
+ xmlattr :test, :xpath => "/foo/bar/text()"
6
+ end
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby -S rspec
2
2
 
3
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
4
5
 
5
6
  require 'mocha'
6
7
  require 'gprov'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gprov
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adrien Thebo
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-11 00:00:00 Z
18
+ date: 2012-05-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: httparty
@@ -104,7 +104,12 @@ files:
104
104
  - lib/gprov.rb
105
105
  - spec/gprov/auth/clientlogin_spec.rb
106
106
  - spec/gprov/connection_spec.rb
107
+ - spec/gprov/provision/entrybase/classmethods_spec.rb
107
108
  - spec/gprov/provision/entrybase_spec.rb
109
+ - spec/gprov/provision/group.rb
110
+ - spec/gprov/provision/orgunit.rb
111
+ - spec/gprov/provision/user.rb
112
+ - spec/lib/fakeentry.rb
108
113
  - spec/spec_helper.rb
109
114
  - LICENSE
110
115
  - Rakefile