identity_crm 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b5daf2f03bf62901623fa17baf56618e8c81751
4
+ data.tar.gz: 1728ffdd8e604689f2fa7de47d8a70ea2ff5ceed
5
+ SHA512:
6
+ metadata.gz: 36ba32b60a7f91e4b05866f161419444ab4ca942d28720419c2e6989ab0f3ba0ae5b8349a98878f8b942d8a5cd218a84f89983f6a9a9bb03495f24e30eb29a42
7
+ data.tar.gz: 89384ff2e6611acf6cc6b61c91e9ae535b8232d46ee1f56d1ce0a7f58562fd25f834793b5a07868c05ebf1dfc4d399b7b6555b6c5a4e5bc285ef05e5d396c636
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Skiftet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+
2
+ # coding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'identity_crm/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'identity_crm'
9
+ spec.version = IdentityCRM::VERSION
10
+ spec.authors = ['Joel E. Svensson']
11
+ spec.email = ['joel.e.svensson@skiftet.org']
12
+ spec.summary = 'A gem for calling the Identity API'
13
+ spec.homepage = 'https://github.com/skiftet/identity-crm-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rest-client', ['>= 2.0', '< 3.0']
22
+ spec.add_dependency 'activesupport', ['~> 5.0']
23
+ end
@@ -0,0 +1,25 @@
1
+
2
+ class IdentityCRM::Client
3
+ def initialize user: nil, token: nil, url: nil
4
+ @url = url.chomp('/')
5
+ raise 'Identity URL is not valid' if URI.parse(@url).host.blank?
6
+ raise 'A username and token is mandatory' unless [user, token].all? &:present?
7
+
8
+ @user = user
9
+ @token = token
10
+ end
11
+
12
+ def base_url
13
+ "#{@url}/api/v2"
14
+ end
15
+
16
+ def self.resource path
17
+ define_method path do
18
+ IdentityCRM::Resource.new "#{base_url}/#{path}", @user, @token
19
+ end
20
+ end
21
+
22
+ resource 'donations'
23
+ resource 'regular_donations'
24
+ resource 'members'
25
+ end
@@ -0,0 +1,44 @@
1
+ class IdentityCRM::Resource
2
+ def initialize url, user, token
3
+ @url = url.chomp('/')
4
+ @user = user
5
+ @token = token
6
+ end
7
+
8
+ def create params: {}, options: {}
9
+ request :post, body: params, options: options
10
+ end
11
+
12
+ def get id = nil, params: {}, options: {}
13
+ request :get, path: id.to_s, query: params, options: options
14
+ end
15
+
16
+ private
17
+
18
+ def request method, path: '', query: {}, options: {}, body: nil
19
+ url = @url
20
+ if path.present?
21
+ url += '/' + path
22
+ end
23
+
24
+ request = {
25
+ method: method,
26
+ url: url,
27
+ user: @user,
28
+ password: @token,
29
+ headers: {
30
+ params: query,
31
+ },
32
+ }
33
+ if body.present?
34
+ request[:payload] = body.as_json
35
+ request[:content_type] = :json
36
+ end
37
+
38
+ if options.include? :timeout
39
+ request[:timeout] = options[:timeout]
40
+ end
41
+
42
+ JSON.parse RestClient::Request.execute(request).body, object_class: OpenStruct
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module IdentityCRM
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,11 @@
1
+ module IdentityCRM end
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext/object/blank'
5
+ require 'uri'
6
+ require 'json'
7
+ require 'rest-client'
8
+
9
+ require_relative 'identity_crm/version'
10
+ require_relative 'identity_crm/resource'
11
+ require_relative 'identity_crm/client'
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: identity_crm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joel E. Svensson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '5.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
47
+ description:
48
+ email:
49
+ - joel.e.svensson@skiftet.org
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - LICENSE
55
+ - identity_crm.gemspec
56
+ - lib/identity_crm.rb
57
+ - lib/identity_crm/client.rb
58
+ - lib/identity_crm/resource.rb
59
+ - lib/identity_crm/version.rb
60
+ homepage: https://github.com/skiftet/identity-crm-ruby
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.6.12
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: A gem for calling the Identity API
84
+ test_files: []