onepagecrm 0.0.5
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 +7 -0
- data/.gitignore +16 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +3 -0
- data/config/config_orig.yml +2 -0
- data/lib/onepagecrm.rb +118 -0
- data/lib/onepagecrm/version.rb +3 -0
- data/onepagecrm.gemspec +24 -0
- data/spec/contacts_spec.rb +53 -0
- data/spec/spec_helper.rb +7 -0
- data/tasks/rspec.rake +3 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25ee36c11deae53ddf22da7b7067fa49ab243343
|
4
|
+
data.tar.gz: 7d3ff98690b9b93eb45dc52bbe348cba5dc5c6b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7dfc223411c7bd0e544506951db3fcc92ce9c33adae2c67557e3aaa199644c403e75d9a0a660662ecbcf4470ce845f572f1270ce5f6eb80a24e1b29be49583a
|
7
|
+
data.tar.gz: 096bd8dc888c1cbdd45cf07994680aff13990fa421f557bead07b5c193c1f54db47a493aa41b9040b91ee94ca9d99c2acb79befe739a74b82661cdbdac93fbca
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in onepagecrm.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
require 'net/http'
|
7
|
+
require 'openssl'
|
8
|
+
require 'base64'
|
9
|
+
require 'json'
|
10
|
+
require 'uri'
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem 'json_spec'
|
14
|
+
gem "codeclimate-test-reporter", require: false
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Peter Armstrong
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
[](https://codeclimate.com/github/peterOnePageCRM/onepagecrm-gem)
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/peterOnePageCRM/onepagecrm-gem)
|
4
|
+
|
5
|
+
# Onepagecrm
|
6
|
+
|
7
|
+
TODO: Write a gem description
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'onepagecrm'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install onepagecrm
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/[my-github-username]/onepagecrm/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/onepagecrm.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'onepagecrm/version'
|
2
|
+
|
3
|
+
class Onepagecrm
|
4
|
+
def initialize(login = nil, password = nil)
|
5
|
+
@url = 'https://app.onepagecrm.com/api/v3/'
|
6
|
+
@login = login
|
7
|
+
@password = password
|
8
|
+
log_in
|
9
|
+
end
|
10
|
+
|
11
|
+
# Login user into API
|
12
|
+
def log_in
|
13
|
+
params = {
|
14
|
+
login: @login,
|
15
|
+
password: @password
|
16
|
+
}
|
17
|
+
|
18
|
+
auth_data = post('login.json', params)
|
19
|
+
@uid = auth_data['data']['user_id']
|
20
|
+
|
21
|
+
@api_key = Base64.decode64(auth_data['data']['auth_key'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def return_uid
|
25
|
+
@uid
|
26
|
+
end
|
27
|
+
|
28
|
+
# Send GET request
|
29
|
+
def get(method, params = {})
|
30
|
+
url = URI.parse(@url + method)
|
31
|
+
get_data = params.empty? ? '' : '?' + params.to_a.map do|x|
|
32
|
+
x[0] + '=' +
|
33
|
+
URI.escape(x[1], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
34
|
+
end.join('&').gsub(/%[0-9A-Fa-f]{2}/) { |x| x.downcase }
|
35
|
+
|
36
|
+
req = Net::HTTP::Get.new(url.request_uri)
|
37
|
+
|
38
|
+
add_auth_headers(req, 'GET', method, params)
|
39
|
+
|
40
|
+
http = Net::HTTP.new(url.host, url.port)
|
41
|
+
http.use_ssl = true
|
42
|
+
result = http.request(req).body
|
43
|
+
JSON.parse result
|
44
|
+
end
|
45
|
+
|
46
|
+
# Send POST request
|
47
|
+
def post(method, params = {})
|
48
|
+
url = URI.parse(@url + method)
|
49
|
+
req = Net::HTTP::Post.new(url.path)
|
50
|
+
req.body = params.to_json
|
51
|
+
req.add_field('Content-Type', 'application/json; charset=utf-8')
|
52
|
+
|
53
|
+
add_auth_headers(req, 'POST', method, params)
|
54
|
+
|
55
|
+
http = Net::HTTP.new(url.host, url.port)
|
56
|
+
http.use_ssl = true
|
57
|
+
result = http.request(req).body
|
58
|
+
JSON.parse result
|
59
|
+
end
|
60
|
+
|
61
|
+
# Send PUT request
|
62
|
+
def put(method, params = {})
|
63
|
+
url = URI.parse(@url + method)
|
64
|
+
req = Net::HTTP::Put.new(url.path)
|
65
|
+
req.body = params.to_json
|
66
|
+
req.add_field('Content-Type', 'application/json; charset=utf-8')
|
67
|
+
add_auth_headers(req, 'PUT', method, params)
|
68
|
+
|
69
|
+
http = Net::HTTP.new(url.host, url.port)
|
70
|
+
http.use_ssl = true
|
71
|
+
result = http.request(req).body
|
72
|
+
JSON.parse result
|
73
|
+
end
|
74
|
+
|
75
|
+
# Send DELETE request
|
76
|
+
def delete(method, params = {})
|
77
|
+
url = URI.parse(@url + method)
|
78
|
+
|
79
|
+
delete_data = params.empty? ? '' : '?' + params.to_a.map do|x|
|
80
|
+
x[0] + '=' +
|
81
|
+
URI.escape(x[1], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
82
|
+
end.join('&').gsub(/%[0-9A-Fa-f]{2}/) { |x| x.downcase }
|
83
|
+
|
84
|
+
req = Net::HTTP::Delete.new(url.request_uri)
|
85
|
+
add_auth_headers(req, 'DELETE', method, params)
|
86
|
+
http = Net::HTTP.new(url.host, url.port)
|
87
|
+
http.use_ssl = true
|
88
|
+
result = http.request(req).body
|
89
|
+
JSON.parse result
|
90
|
+
end
|
91
|
+
|
92
|
+
# Add authentication headers
|
93
|
+
def add_auth_headers(req, http_method, api_method, params)
|
94
|
+
return if @uid.nil? || @api_key.nil?
|
95
|
+
|
96
|
+
url_to_sign = @url + api_method
|
97
|
+
params_to_sign = params.empty? ? nil : URI.encode_www_form(params)
|
98
|
+
url_to_sign += '?' + params_to_sign unless params_to_sign.nil? || %w(POST PUT).include?(http_method)
|
99
|
+
|
100
|
+
# puts url_to_sign
|
101
|
+
timestamp = Time.now.to_i.to_s
|
102
|
+
|
103
|
+
token = create_signature(@uid, @api_key, timestamp, http_method, url_to_sign, params)
|
104
|
+
|
105
|
+
req.add_field('X-OnePageCRM-UID', @uid)
|
106
|
+
req.add_field('X-OnePageCRM-TS', timestamp)
|
107
|
+
req.add_field('X-OnePageCRM-Auth', token)
|
108
|
+
req.add_field('X-OnePageCRM-Source', 'lead_clip_chrome')
|
109
|
+
end
|
110
|
+
|
111
|
+
def create_signature(uid, api_key, timestamp, request_type, request_url, request_body)
|
112
|
+
request_url_hash = Digest::SHA1.hexdigest request_url
|
113
|
+
request_body_hash = Digest::SHA1.hexdigest request_body.to_json
|
114
|
+
signature_message = [uid, timestamp, request_type.upcase, request_url_hash].join '.'
|
115
|
+
signature_message += ('.' + request_body_hash) unless request_body.empty?
|
116
|
+
OpenSSL::HMAC.hexdigest('sha256', api_key, signature_message).to_s
|
117
|
+
end
|
118
|
+
end
|
data/onepagecrm.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'onepagecrm/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'onepagecrm'
|
8
|
+
spec.version = Onepagecrm::VERSION
|
9
|
+
spec.authors = ['Peter Armstrong']
|
10
|
+
spec.email = ['peter@onepagecrm.com']
|
11
|
+
spec.summary = %q{Basic Gem for OnePageCRM.}
|
12
|
+
spec.description = %q{Basic Gem for OnePageCRM.}
|
13
|
+
spec.homepage = ''
|
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_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json_spec'
|
3
|
+
|
4
|
+
describe Onepagecrm do
|
5
|
+
subject { Onepagecrm.new(TEST_CONFIG['login'], TEST_CONFIG['password']) }
|
6
|
+
|
7
|
+
describe '#create_contact' do
|
8
|
+
it 'creates a new contact' do
|
9
|
+
new_contact_details = ({
|
10
|
+
'first_name' => 'yes',
|
11
|
+
'last_name' => 'address',
|
12
|
+
'company_name' => 'ACME&inc',
|
13
|
+
'starred' => false,
|
14
|
+
'tags' => %w(api_test1 api_test2),
|
15
|
+
'emails' => [{
|
16
|
+
'type' => 'work',
|
17
|
+
'value' => 'johnny@exammmple.com' }],
|
18
|
+
'phones' => [{
|
19
|
+
'type' => 'work',
|
20
|
+
'value' => '00033353' }],
|
21
|
+
'urls' => [{
|
22
|
+
'type' => 'website',
|
23
|
+
'value' => 'lsdkiteboarding.com' }],
|
24
|
+
'background' => 'BACKGROUND',
|
25
|
+
'job_title' => 'JOBTITLE',
|
26
|
+
'address_list' => [
|
27
|
+
'city' => 'San Francisco',
|
28
|
+
'state' => 'CA'
|
29
|
+
]
|
30
|
+
})
|
31
|
+
|
32
|
+
new_contact = subject.post('contacts.json', new_contact_details)['data']
|
33
|
+
new_contact_id = new_contact['contact']['id']
|
34
|
+
got_deets = subject.get("contacts/#{new_contact_id}.json")['data']['contact']
|
35
|
+
expect(got_deets['first_name']).to eq(new_contact_details['first_name'])
|
36
|
+
|
37
|
+
details_without_address = new_contact_details.reject { |k| k == 'address_list' }
|
38
|
+
|
39
|
+
details_without_address.each do |k, _v|
|
40
|
+
expect(got_deets[k]).to eq(new_contact_details[k])
|
41
|
+
end
|
42
|
+
|
43
|
+
# check address
|
44
|
+
address = got_deets['address_list'][0]
|
45
|
+
expect(address['city']).to eq 'San Francisco'
|
46
|
+
expect(address['state']).to eq 'CA'
|
47
|
+
|
48
|
+
# delete contact
|
49
|
+
subject.delete("contacts/#{new_contact_id}.json")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onepagecrm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Armstrong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Basic Gem for OnePageCRM.
|
56
|
+
email:
|
57
|
+
- peter@onepagecrm.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- config/config_orig.yml
|
68
|
+
- lib/onepagecrm.rb
|
69
|
+
- lib/onepagecrm/version.rb
|
70
|
+
- onepagecrm.gemspec
|
71
|
+
- spec/contacts_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
- tasks/rspec.rake
|
74
|
+
homepage: ''
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Basic Gem for OnePageCRM.
|
98
|
+
test_files:
|
99
|
+
- spec/contacts_spec.rb
|
100
|
+
- spec/spec_helper.rb
|