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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbe6f59cb6fc11c4e85ca5073ef1c6ef1e66abb0
4
- data.tar.gz: 14a8dde7bd765bb9c7d98275b9fc6313ffb52867
3
+ metadata.gz: 7cfa1149476a5896453ceb5b9a1338e8086179c8
4
+ data.tar.gz: f816b49e711481291aa6f747b7cf073108e580c2
5
5
  SHA512:
6
- metadata.gz: b35e8244019544a13e2f78b9815ac5cdf631e708f8cfa4ddd2c5053a37fa435b7eef42f9d545ebcf873b22a55b6072502b3a5e09ebabccd7b07739b0ec684205
7
- data.tar.gz: a52d8f160cf41f3b6f49d4581d825d63a56de7b9153bf42921b77e039f41ef4b12349733cf41c84e10a49fa0eb3ae44518d5454c797ac61aad9ae51b6d490bdf
6
+ metadata.gz: 722be9f5dc41b116331dad7d1d198141d210176e47c457aaec892b994d08b90156204978acc93d90e633c336c8f1e05a05e08d72ea66e7d5451115c0080af061
7
+ data.tar.gz: 51764fa77039ef8e06f3b0e85be14976ae4c96df8dce4c052f44d60e4a280d69bcb50b03551ee087e50583fa781406503057fb1f9bb130fd82c069110eeae4e1
data/.gitignore CHANGED
@@ -1,2 +1,4 @@
1
1
  /pkg
2
2
  .rvmrc
3
+ .byebug_history
4
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- civicrm (1.0.4)
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 (5.2.0)
14
- activesupport (= 5.2.0)
15
- activesupport (5.2.0)
16
- concurrent-ruby (~> 1.0, >= 1.0.2)
17
- i18n (>= 0.7, < 2)
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.2.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 (1.0.1)
30
+ i18n (0.9.5)
27
31
  concurrent-ruby (~> 1.0)
28
- metaclass (0.0.1)
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 (2.13.0)
43
- rspec-core (~> 2.13.0)
44
- rspec-expectations (~> 2.13.0)
45
- rspec-mocks (~> 2.13.0)
46
- rspec-core (2.13.1)
47
- rspec-expectations (2.13.0)
48
- diff-lcs (>= 1.1.3, < 2.0)
49
- rspec-mocks (2.13.0)
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
- * $ gem install civicrm
5
+ ```
6
+ $ gem install civicrm
7
+ ```
4
8
 
5
9
  ## Getting started
6
10
 
7
11
  ```ruby
8
- * CiviCrm.site_key = 'YOUR_SITE_KEY'
9
- * // More info about site_key:
10
- * // http://wiki.civicrm.org/confluence/display/CRMDOC43/Managing+Scheduled+Jobs
11
- * CiviCrm.api_base = 'https://www.example.org/path/to/civi/codebase/'
12
- * CiviCrm.authenticate('demo', 'demo')
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
- * CiviCrm::Contact.all # get list of contacts
19
- * CiviCrm::Contact.create(contact_type: 'Organization', organization_name: 'test') # create contact
20
- * CiviCrm::Contact.find(1).delete # find and delete
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
- * http://wiki.civicrm.org/confluence/display/CRMDOC43/REST+interface
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('mocha')
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")
@@ -1,3 +1,3 @@
1
1
  module CiviCrm
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'
3
3
  end
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 weird elements
5
+ # CiviCRM <Result>s sometimes contain invalid elements
6
6
  # like <preferred_communication_method><0></0></ ...
7
- # that Nokogiri::XML can't hang with. Get rid of them before
8
- # parsing.
7
+ # Get rid of them before parsing.
9
8
  fixed_text = text.to_s.
10
9
  gsub("\n", "").
11
- gsub(/<(\w|_)+>\s*<\d+><\/\d+>\s*<\/(\w|_)+>/, "")
10
+ gsub(/<\d+>(.*?)<\/\d+>/, "")
12
11
 
13
12
  doc = Nokogiri::XML.parse(fixed_text)
14
13
 
@@ -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
- before :all do
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
- @client.expects(:get).never
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
- @client.expects(:post).once.returns(test_response(api_key: 'test'))
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(OpenStruct.new(code: 400, body: 'message'))
28
- RestClient::Request.stubs(:execute).raises(exception)
29
- expect { @client.execute!({}) }.to raise_error(CiviCrm::Errors::BadRequest)
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(OpenStruct.new(code: 401, body: 'message'))
34
- RestClient::Request.stubs(:execute).raises(exception)
35
- expect { @client.execute!({}) }.to raise_error(CiviCrm::Errors::Unauthorized)
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(OpenStruct.new(code: 403, body: 'message'))
40
- RestClient::Request.stubs(:execute).raises(exception)
41
- expect { @client.execute!({}) }.to raise_error(CiviCrm::Errors::Forbidden)
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(OpenStruct.new(code: 404, body: 'message'))
46
- RestClient::Request.stubs(:execute).raises(exception)
47
- expect { @client.execute!({}) }.to raise_error(CiviCrm::Errors::NotFound)
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(OpenStruct.new(code: 500, body: 'message'))
52
- RestClient::Request.stubs(:execute).raises(exception)
53
- expect { @client.execute!({}) }.to raise_error(CiviCrm::Errors::InternalError)
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
- RestClient::Request.stubs(:execute).returns('test')
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.expects(:post).once.returns(test_response(test_contact))
10
- c = CiviCrm::Contact.create
11
- c.should be_a_kind_of(CiviCrm::Contact)
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
- config.mock_with :mocha
8
- end
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
@@ -20,8 +20,9 @@ module CiviCrm
20
20
  end
21
21
  end
22
22
  end
23
+
23
24
  def authorized_civicrm_client
24
25
  CiviCrm.api_key = 'civicrm'
25
26
  CiviCrm.site_key = 'civicrm'
26
- CiviCrm::Client.mock_rest_client(mock)
27
- end
27
+ CiviCrm::Client.mock_rest_client(double)
28
+ end
@@ -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
- m = mock
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.expects(:get).once.returns(test_response(test_response_hash))
8
- c = subject.all
7
+ expect(client).
8
+ to receive(:get).
9
+ exactly(:once).
10
+ and_return(test_response(test_response_hash))
9
11
 
10
- c.should be_a_kind_of(Array)
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.expects(:get).once.returns(test_response(test_contact({name: "foo"})))
19
- client.expects(:put).once.returns(test_response(test_contact({name: "bar"})))
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.should == "foo"
32
+ expect(c.name).to eq("foo")
33
+
22
34
  c.name = "bar"
23
35
  c.save
24
- c.name.should == "bar"
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.expects(:get).once.returns(test_response(test_contact({name: "foo"})))
33
- client.expects(:delete).once.returns(test_response(test_contact({name: "bar"})))
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.5
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-07-27 00:00:00.000000000 Z
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: '0'
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: '0'
96
+ version: '3.8'
97
97
  - !ruby/object:Gem::Dependency
98
- name: mocha
98
+ name: byebug
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="