civicrm 1.0.5 → 1.0.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +28 -21
- data/README.md +30 -12
- data/civicrm.gemspec +2 -2
- data/lib/civicrm/version.rb +1 -1
- data/lib/civicrm/xml.rb +3 -4
- data/spec/requests/base_spec.rb +26 -27
- data/spec/resources/contact_spec.rb +8 -4
- data/spec/spec_helper.rb +12 -2
- data/spec/support/civicrm.rb +3 -2
- data/spec/support/civicrm_responses.rb +2 -6
- data/spec/support/test_matchers.rb +31 -10
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cfa1149476a5896453ceb5b9a1338e8086179c8
|
4
|
+
data.tar.gz: f816b49e711481291aa6f747b7cf073108e580c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 722be9f5dc41b116331dad7d1d198141d210176e47c457aaec892b994d08b90156204978acc93d90e633c336c8f1e05a05e08d72ea66e7d5451115c0080af061
|
7
|
+
data.tar.gz: 51764fa77039ef8e06f3b0e85be14976ae4c96df8dce4c052f44d60e4a280d69bcb50b03551ee087e50583fa781406503057fb1f9bb130fd82c069110eeae4e1
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
civicrm (1.0.
|
4
|
+
civicrm (1.0.5)
|
5
5
|
activemodel
|
6
6
|
activesupport
|
7
7
|
nokogiri
|
@@ -10,27 +10,29 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activemodel (
|
14
|
-
activesupport (=
|
15
|
-
|
16
|
-
|
17
|
-
i18n (
|
13
|
+
activemodel (4.1.16)
|
14
|
+
activesupport (= 4.1.16)
|
15
|
+
builder (~> 3.1)
|
16
|
+
activesupport (4.1.16)
|
17
|
+
i18n (~> 0.6, >= 0.6.9)
|
18
|
+
json (~> 1.7, >= 1.7.7)
|
18
19
|
minitest (~> 5.1)
|
20
|
+
thread_safe (~> 0.1)
|
19
21
|
tzinfo (~> 1.1)
|
22
|
+
builder (3.2.3)
|
23
|
+
byebug (10.0.2)
|
20
24
|
concurrent-ruby (1.0.5)
|
21
|
-
diff-lcs (1.
|
25
|
+
diff-lcs (1.3)
|
22
26
|
domain_name (0.5.20180417)
|
23
27
|
unf (>= 0.0.5, < 1.0.0)
|
24
28
|
http-cookie (1.0.3)
|
25
29
|
domain_name (~> 0.5)
|
26
|
-
i18n (
|
30
|
+
i18n (0.9.5)
|
27
31
|
concurrent-ruby (~> 1.0)
|
28
|
-
|
32
|
+
json (1.8.6)
|
29
33
|
mime-types (2.99.3)
|
30
34
|
mini_portile2 (2.3.0)
|
31
35
|
minitest (5.11.3)
|
32
|
-
mocha (0.10.5)
|
33
|
-
metaclass (~> 0.0.1)
|
34
36
|
netrc (0.11.0)
|
35
37
|
nokogiri (1.8.4)
|
36
38
|
mini_portile2 (~> 2.3.0)
|
@@ -39,14 +41,19 @@ GEM
|
|
39
41
|
http-cookie (>= 1.0.2, < 2.0)
|
40
42
|
mime-types (>= 1.16, < 3.0)
|
41
43
|
netrc (~> 0.7)
|
42
|
-
rspec (
|
43
|
-
rspec-core (~>
|
44
|
-
rspec-expectations (~>
|
45
|
-
rspec-mocks (~>
|
46
|
-
rspec-core (
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
rspec (3.8.0)
|
45
|
+
rspec-core (~> 3.8.0)
|
46
|
+
rspec-expectations (~> 3.8.0)
|
47
|
+
rspec-mocks (~> 3.8.0)
|
48
|
+
rspec-core (3.8.0)
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-expectations (3.8.1)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-mocks (3.8.0)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.8.0)
|
56
|
+
rspec-support (3.8.0)
|
50
57
|
thread_safe (0.3.6)
|
51
58
|
tzinfo (1.2.5)
|
52
59
|
thread_safe (~> 0.1)
|
@@ -58,10 +65,10 @@ PLATFORMS
|
|
58
65
|
ruby
|
59
66
|
|
60
67
|
DEPENDENCIES
|
68
|
+
byebug
|
61
69
|
civicrm!
|
62
|
-
mocha
|
63
70
|
rake
|
64
|
-
rspec
|
71
|
+
rspec (~> 3.8)
|
65
72
|
|
66
73
|
BUNDLED WITH
|
67
74
|
1.12.5
|
data/README.md
CHANGED
@@ -1,31 +1,49 @@
|
|
1
|
+
# CiviCRM Client
|
2
|
+
|
1
3
|
## Installation
|
2
4
|
|
3
|
-
|
5
|
+
```
|
6
|
+
$ gem install civicrm
|
7
|
+
```
|
4
8
|
|
5
9
|
## Getting started
|
6
10
|
|
7
11
|
```ruby
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
# Required config
|
13
|
+
CiviCrm.api_base = "https://www.example.org/path/to/civi/codebase/"
|
14
|
+
CiviCrm.site_key = "YOUR_SITE_KEY"
|
15
|
+
|
16
|
+
# Authenticate with username/password
|
17
|
+
CiviCrm.authenticate("username", "password")
|
18
|
+
|
19
|
+
# OR, authenticate with API key
|
20
|
+
CiviCrm.api_key = "..."
|
13
21
|
```
|
14
22
|
|
15
23
|
## CiviCrm Objects
|
16
24
|
|
17
25
|
```ruby
|
18
|
-
|
19
|
-
|
20
|
-
|
26
|
+
# Get list of contacts
|
27
|
+
CiviCrm::Contact.all
|
28
|
+
|
29
|
+
# Create contact
|
30
|
+
CiviCrm::Contact.create(contact_type: "Organization", organization_name: "test")
|
31
|
+
|
32
|
+
# Find and delete
|
33
|
+
CiviCrm::Contact.find(1).delete
|
21
34
|
```
|
22
35
|
|
23
36
|
## Testing
|
37
|
+
|
24
38
|
```
|
25
|
-
rspec spec
|
39
|
+
$ bundle exec rspec spec
|
26
40
|
```
|
27
41
|
|
28
42
|
## Useful links
|
29
43
|
|
30
|
-
*
|
31
|
-
* http://drupal.demo.civicrm.org/civicrm/api/explorer
|
44
|
+
* https://docs.civicrm.org/dev/en/latest/api/interfaces/#rest-interface
|
45
|
+
* http://drupal.demo.civicrm.org/civicrm/api/explorer
|
46
|
+
|
47
|
+
## Acknowledgements
|
48
|
+
|
49
|
+
Created by [Iskander Haziev](https://github.com/gvalmon). Maintained by [EFF](https://www.eff.org/).
|
data/civicrm.gemspec
CHANGED
@@ -19,8 +19,8 @@ spec = Gem::Specification.new do |s|
|
|
19
19
|
s.add_dependency('nokogiri')
|
20
20
|
|
21
21
|
s.add_development_dependency('rake')
|
22
|
-
s.add_development_dependency('rspec')
|
23
|
-
s.add_development_dependency('
|
22
|
+
s.add_development_dependency('rspec', '~> 3.8')
|
23
|
+
s.add_development_dependency('byebug')
|
24
24
|
|
25
25
|
s.files = `git ls-files`.split("\n")
|
26
26
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
data/lib/civicrm/version.rb
CHANGED
data/lib/civicrm/xml.rb
CHANGED
@@ -2,13 +2,12 @@ module CiviCrm
|
|
2
2
|
class XML
|
3
3
|
class << self
|
4
4
|
def parse(text)
|
5
|
-
# CiviCRM <Result>s sometimes contain
|
5
|
+
# CiviCRM <Result>s sometimes contain invalid elements
|
6
6
|
# like <preferred_communication_method><0></0></ ...
|
7
|
-
#
|
8
|
-
# parsing.
|
7
|
+
# Get rid of them before parsing.
|
9
8
|
fixed_text = text.to_s.
|
10
9
|
gsub("\n", "").
|
11
|
-
gsub(
|
10
|
+
gsub(/<\d+>(.*?)<\/\d+>/, "")
|
12
11
|
|
13
12
|
doc = Nokogiri::XML.parse(fixed_text)
|
14
13
|
|
data/spec/requests/base_spec.rb
CHANGED
@@ -1,62 +1,61 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'rest_client'
|
3
3
|
require 'ostruct'
|
4
|
+
|
4
5
|
describe "API Bindings" do
|
5
6
|
|
6
|
-
|
7
|
-
@client = authorized_civicrm_client
|
8
|
-
end
|
7
|
+
let(:client){ authorized_civicrm_client }
|
9
8
|
|
10
9
|
it "should not fetch from network while initializing a new Resource" do
|
11
|
-
|
10
|
+
expect(client).not_to receive(:get)
|
12
11
|
CiviCrm::Contact.new(id: "someid")
|
13
12
|
end
|
14
13
|
|
15
14
|
it "should run authentication" do
|
16
|
-
|
15
|
+
expect(client).
|
16
|
+
to receive(:post).
|
17
|
+
exactly(:once).
|
18
|
+
and_return(test_response(api_key: 'test'))
|
19
|
+
|
17
20
|
CiviCrm.authenticate("test", "test")
|
18
21
|
end
|
19
22
|
|
20
23
|
describe "exception handler" do
|
21
|
-
|
22
|
-
before :all do
|
23
|
-
@client = CiviCrm::Client
|
24
|
-
end
|
24
|
+
let(:client){ CiviCrm::Client }
|
25
25
|
|
26
26
|
it "should raise CiviCrm::Errors::BadRequest on 400" do
|
27
|
-
exception = RestClient::Exception.new(
|
28
|
-
RestClient::Request.
|
29
|
-
expect {
|
27
|
+
exception = RestClient::Exception.new(nil, 400)
|
28
|
+
expect(RestClient::Request).to receive(:execute).and_raise(exception)
|
29
|
+
expect { client.execute!({}) }.to raise_error(CiviCrm::Errors::BadRequest)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should raise CiviCrm::Errors::Unauthorized on 401" do
|
33
|
-
exception = RestClient::Exception.new(
|
34
|
-
RestClient::Request.
|
35
|
-
expect {
|
33
|
+
exception = RestClient::Exception.new(nil, 401)
|
34
|
+
expect(RestClient::Request).to receive(:execute).and_raise(exception)
|
35
|
+
expect { client.execute!({}) }.to raise_error(CiviCrm::Errors::Unauthorized)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should raise CiviCrm::Errors::Forbidden on 403" do
|
39
|
-
exception = RestClient::Exception.new(
|
40
|
-
RestClient::Request.
|
41
|
-
expect {
|
39
|
+
exception = RestClient::Exception.new(nil, 403)
|
40
|
+
expect(RestClient::Request).to receive(:execute).and_raise(exception)
|
41
|
+
expect { client.execute!({}) }.to raise_error(CiviCrm::Errors::Forbidden)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should raise CiviCrm::Errors::NotFound on 404" do
|
45
|
-
exception = RestClient::Exception.new(
|
46
|
-
RestClient::Request.
|
47
|
-
expect {
|
45
|
+
exception = RestClient::Exception.new(nil, 404)
|
46
|
+
expect(RestClient::Request).to receive(:execute).and_raise(exception)
|
47
|
+
expect { client.execute!({}) }.to raise_error(CiviCrm::Errors::NotFound)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should raise CiviCrm::Errors::InternalError on 500" do
|
51
|
-
exception = RestClient::Exception.new(
|
52
|
-
RestClient::Request.
|
53
|
-
expect {
|
51
|
+
exception = RestClient::Exception.new(nil, 500)
|
52
|
+
expect(RestClient::Request).to receive(:execute).and_raise(exception)
|
53
|
+
expect { client.execute!({}) }.to raise_error(CiviCrm::Errors::InternalError)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should raise CiviCrm::Errors::Unauthorized if site_key is not provided" do
|
57
57
|
CiviCrm.site_key = nil
|
58
|
-
|
59
|
-
expect { @client.request('get', 'test') }.to raise_error(CiviCrm::Errors::Unauthorized)
|
58
|
+
expect { client.request('get', 'test') }.to raise_error(CiviCrm::Errors::Unauthorized)
|
60
59
|
end
|
61
60
|
end
|
62
|
-
end
|
61
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
|
2
3
|
describe CiviCrm::Contact do
|
3
4
|
it { should be_listable_resource }
|
4
5
|
#it { should be_updatable_resource }
|
@@ -6,8 +7,11 @@ describe CiviCrm::Contact do
|
|
6
7
|
it "should return contact on create" do
|
7
8
|
client = authorized_civicrm_client
|
8
9
|
|
9
|
-
client
|
10
|
-
|
11
|
-
|
10
|
+
expect(client).
|
11
|
+
to receive(:post).
|
12
|
+
exactly(:once).
|
13
|
+
and_return(test_response(test_contact))
|
14
|
+
|
15
|
+
expect(CiviCrm::Contact.create).to be_a_kind_of(CiviCrm::Contact)
|
12
16
|
end
|
13
|
-
end
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
|
+
require 'byebug'
|
2
|
+
|
1
3
|
require 'civicrm'
|
2
4
|
require 'support/civicrm'
|
3
5
|
require 'support/civicrm_responses'
|
4
6
|
require 'support/test_matchers'
|
7
|
+
|
5
8
|
RSpec.configure do |config|
|
6
9
|
include CiviCrm::TestResponses
|
7
|
-
|
8
|
-
|
10
|
+
|
11
|
+
config.mock_with :rspec do |mocks|
|
12
|
+
mocks.verify_partial_doubles = true
|
13
|
+
end
|
14
|
+
|
15
|
+
config.expect_with :rspec do |expectations|
|
16
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
17
|
+
end
|
18
|
+
end
|
data/spec/support/civicrm.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
module CiviCrm::TestResponses
|
2
2
|
def test_response(body, code = 200)
|
3
3
|
body = CiviCrm::XML.encode(body) if !(body.kind_of? String)
|
4
|
-
|
5
|
-
m.instance_variable_set('@data', { body: body, code: code})
|
6
|
-
def m.body; @data[:body]; end
|
7
|
-
def m.code; @data[:code]; end
|
8
|
-
m
|
4
|
+
double(body: body, code: code)
|
9
5
|
end
|
10
6
|
|
11
7
|
def test_contact(params = {})
|
@@ -28,4 +24,4 @@
|
|
28
24
|
:values => [test_contact, test_contact, test_contact]
|
29
25
|
}
|
30
26
|
end
|
31
|
-
end
|
27
|
+
end
|
@@ -4,34 +4,55 @@ RSpec::Matchers.define :be_listable_resource do |expected|
|
|
4
4
|
subject = actual.class
|
5
5
|
test_response_hash = send(:"test_#{subject.name.demodulize.underscore}_array")
|
6
6
|
|
7
|
-
client
|
8
|
-
|
7
|
+
expect(client).
|
8
|
+
to receive(:get).
|
9
|
+
exactly(:once).
|
10
|
+
and_return(test_response(test_response_hash))
|
9
11
|
|
10
|
-
|
12
|
+
expect(subject.all).to be_a_kind_of(Array)
|
11
13
|
end
|
12
14
|
end
|
15
|
+
|
13
16
|
RSpec::Matchers.define :be_updatable_resource do |expected|
|
14
17
|
match do |actual|
|
15
18
|
client = authorized_civicrm_client
|
16
19
|
subject = actual.class
|
17
20
|
|
18
|
-
client
|
19
|
-
|
21
|
+
expect(client).
|
22
|
+
to receive(:get).
|
23
|
+
exactly(:once).
|
24
|
+
and_return(test_response(test_contact({name: "foo"})))
|
25
|
+
|
26
|
+
expect(client).
|
27
|
+
to receive(:put).
|
28
|
+
exactly(:once).
|
29
|
+
and_return(test_response(test_contact({name: "bar"})))
|
30
|
+
|
20
31
|
c = subject.find("resource_id")
|
21
|
-
c.name.
|
32
|
+
expect(c.name).to eq("foo")
|
33
|
+
|
22
34
|
c.name = "bar"
|
23
35
|
c.save
|
24
|
-
c.name.
|
36
|
+
expect(c.name).to eq("bar")
|
25
37
|
end
|
26
38
|
end
|
39
|
+
|
27
40
|
RSpec::Matchers.define :be_deleteable_resource do |expected|
|
28
41
|
match do |actual|
|
29
42
|
client = authorized_civicrm_client
|
30
43
|
subject = actual.class
|
31
44
|
|
32
|
-
client
|
33
|
-
|
45
|
+
expect(client).
|
46
|
+
to receive(:get).
|
47
|
+
exactly(:once).
|
48
|
+
and_return(test_response(test_contact({name: "foo"})))
|
49
|
+
|
50
|
+
expect(client).
|
51
|
+
to receive(:delete).
|
52
|
+
exactly(:once).
|
53
|
+
and_return(test_response(test_contact({name: "bar"})))
|
54
|
+
|
34
55
|
c = subject.find("resource_id")
|
35
56
|
c.delete
|
36
57
|
end
|
37
|
-
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: civicrm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Haziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -84,18 +84,18 @@ dependencies:
|
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '3.8'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '3.8'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: byebug
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|