googlecontacts 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'pp'
7
+
8
+ require 'fakeweb'
9
+ FakeWeb.allow_net_connect = false
10
+
11
+ require 'google_contacts'
12
+ include GoogleContacts
13
+
14
+ module Helpers
15
+ def consumer
16
+ ::OAuth::AccessToken.new(Auth.consumer, 'key', 'secret')
17
+ end
18
+
19
+ def wrapper
20
+ @wrapper ||= Wrapper.new(consumer)
21
+ end
22
+
23
+ def asset(file)
24
+ File.read File.join(File.dirname(__FILE__), "assets", "#{file}.xml")
25
+ end
26
+
27
+ def parsed_asset(file)
28
+ Nokogiri::XML.parse asset(file)
29
+ end
30
+ end
31
+
32
+ Spec::Runner.configure do |config|
33
+ config.include(Helpers)
34
+ config.mock_with :mocha
35
+ end
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Wrapper do
4
+ describe "fetching" do
5
+ it "should be able to get list of contacts" do
6
+ FakeWeb.register_uri(:get,
7
+ 'http://www.google.com/m8/feeds/contacts/default/full',
8
+ :body => asset('contacts_full')
9
+ )
10
+
11
+ result = wrapper.contacts.find(:all)
12
+ result.should have(1).contact
13
+ result.first.should be_a Contact
14
+ end
15
+
16
+ it "should be able to get list of groups" do
17
+ FakeWeb.register_uri(:get,
18
+ 'http://www.google.com/m8/feeds/groups/default/full',
19
+ :body => asset('groups_full')
20
+ )
21
+
22
+ result = wrapper.groups.find(:all)
23
+ result.should have(2).groups
24
+ result.first.should be_a Group
25
+ end
26
+ end
27
+
28
+ describe "flushing" do
29
+ it "should not allow nesting of #batch" do
30
+ lambda {
31
+ wrapper.batch { wrapper.batch { } }
32
+ }.should raise_error(/not allowed/i)
33
+ end
34
+
35
+ it "should collect operations in a batch" do
36
+ wrapper.expects(:post).never
37
+ document = wrapper.batch(:return_documents => true) do
38
+ wrapper.contacts.build.save
39
+ wrapper.contacts.build.save
40
+ end.first
41
+
42
+ document.xpath('.//xmlns:entry').should have(2).entries
43
+ document.xpath('.//batch:operation').each do |operation|
44
+ operation['type'].should == 'insert'
45
+ end
46
+ end
47
+
48
+ it "should flush batches in chunks of 100" do
49
+ wrapper.expects(:post).with(regexp_matches(%r!/contacts/!), is_a(String)).twice
50
+ wrapper.batch do
51
+ contact = wrapper.contacts.build
52
+ 101.times { contact.save }
53
+ end
54
+ end
55
+
56
+ it "should raise when mixing contacts and groups in one batch" do
57
+ lambda {
58
+ wrapper.batch {
59
+ wrapper.contacts.build.save
60
+ wrapper.groups.build.save
61
+ }
62
+ }.should raise_error(/cannot mix/i)
63
+ end
64
+
65
+ it "should POST a single-operation batch to contacts when not batching" do
66
+ wrapper.expects(:post).with(regexp_matches(%r!/contacts/!), is_a(String))
67
+ wrapper.contacts.build.save
68
+ end
69
+
70
+ it "should POST a single-operation batch to groups when not batching" do
71
+ wrapper.expects(:post).with(regexp_matches(%r!/groups/!), is_a(String))
72
+ wrapper.groups.build.save
73
+ end
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: googlecontacts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pieter Noordhuis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-26 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.4
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: nokogiri
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.4.1
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: oauth
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.3.6
54
+ version:
55
+ description: Google Contacts API implementation
56
+ email: pcnoordhuis@gmail.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.md
64
+ - README.rdoc
65
+ files:
66
+ - .document
67
+ - .gitignore
68
+ - LICENSE
69
+ - README.rdoc
70
+ - Rakefile
71
+ - VERSION
72
+ - lib/google_contacts.rb
73
+ - lib/google_contacts/auth.rb
74
+ - lib/google_contacts/base.rb
75
+ - lib/google_contacts/contact.rb
76
+ - lib/google_contacts/group.rb
77
+ - lib/google_contacts/proxies/array.rb
78
+ - lib/google_contacts/proxies/emails.rb
79
+ - lib/google_contacts/proxies/hash.rb
80
+ - lib/google_contacts/wrapper.rb
81
+ - spec/assets/contacts_full.xml
82
+ - spec/assets/groups_full.xml
83
+ - spec/base_spec.rb
84
+ - spec/contact_spec.rb
85
+ - spec/group_spec.rb
86
+ - spec/proxies/array_spec.rb
87
+ - spec/proxies/emails_spec.rb
88
+ - spec/proxies/hash_spec.rb
89
+ - spec/spec.opts
90
+ - spec/spec_helper.rb
91
+ - spec/wrapper_spec.rb
92
+ - README.md
93
+ has_rdoc: true
94
+ homepage: http://github.com/pietern/googlecontacts
95
+ licenses: []
96
+
97
+ post_install_message:
98
+ rdoc_options:
99
+ - --charset=UTF-8
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ version:
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ version:
114
+ requirements: []
115
+
116
+ rubyforge_project:
117
+ rubygems_version: 1.3.5
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Contacts API on steroids
121
+ test_files:
122
+ - spec/base_spec.rb
123
+ - spec/contact_spec.rb
124
+ - spec/group_spec.rb
125
+ - spec/proxies/array_spec.rb
126
+ - spec/proxies/emails_spec.rb
127
+ - spec/proxies/hash_spec.rb
128
+ - spec/spec_helper.rb
129
+ - spec/wrapper_spec.rb