onepagecrm 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2859dfc423493ac5aef46f2dc87faa6601d44ccb
4
- data.tar.gz: d3f35388dec43c2472f12f99e9b91b418f872f38
3
+ metadata.gz: ea189d76157c7ff7072624e96c36cf55ed81156c
4
+ data.tar.gz: d99f8f3f82ee4f72b51605bc5aa4dc4d08f605a1
5
5
  SHA512:
6
- metadata.gz: d9683174012ce7b0df6e3d76a81a445077910f244d762d14d8790904a6b8b92fe820acc274bf29f427e0256785d08b6e08e0120ece9057bf544ae824f2630699
7
- data.tar.gz: 8d399642d5a675af251c91e6615345e4ceaa719264c57b848ce5392622ca76956000826d2ad353fd337448fe392dc8766b1a322347af975ddfd942cbf76870f2
6
+ metadata.gz: 15f1d9edf2f48b5e22e2cc3971e9288978cc572c090580f4769421c7cb3f315584a04395c6b1c96ef22f748fabba7ec832997c46c633803483b8b2d8eafd28cc
7
+ data.tar.gz: 2b4bdb12542d3ed750589a7486284878cbb314243fcbf288fc8592143beb12dacbd0edf141ae66003d618b0feffcbd656a2392c9c24c88301ca0326995d884cf
@@ -8,45 +8,38 @@ require 'uri'
8
8
  class Onepagecrm
9
9
  def initialize(login = nil, password = nil)
10
10
  @url = 'https://app.onepagecrm.com/api/v3/'
11
- @login = login
12
- @password = password
13
- log_in
11
+ log_in(login, password)
14
12
  end
15
13
 
16
14
  # Login user into API
17
- def log_in
18
- params = {
19
- login: @login,
20
- password: @password
21
- }
22
-
15
+ def log_in(login, password)
16
+ params = { login: login, password: password }
23
17
  auth_data = post('login.json', params)
24
18
  @uid = auth_data['data']['user_id']
25
-
26
19
  @api_key = Base64.decode64(auth_data['data']['auth_key'])
27
20
  end
28
21
 
29
- def return_uid
30
- @uid
31
- end
32
-
33
22
  # Send GET request
34
23
  def get(method, params = {})
35
24
  url = URI.parse(@url + method)
36
- get_data = params.empty? ? '' : '?' + params.to_a.map do|x|
37
- x[0] + '=' +
38
- URI.escape(x[1], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
39
- end.join('&').gsub(/%[0-9A-Fa-f]{2}/) { |x| x.downcase }
40
-
41
25
  req = Net::HTTP::Get.new(url.request_uri)
42
-
43
26
  add_auth_headers(req, 'GET', method, params)
27
+ http = Net::HTTP.new(url.host, url.port)
28
+ http.use_ssl = true
29
+ result = http.request(req).body
30
+ JSON.parse result
31
+ end
44
32
 
33
+ # Send DELETE request
34
+ def delete(method, params = {})
35
+ url = URI.parse(@url + method)
36
+ req = Net::HTTP::Delete.new(url.request_uri)
37
+ add_auth_headers(req, 'DELETE', method, params)
45
38
  http = Net::HTTP.new(url.host, url.port)
46
39
  http.use_ssl = true
47
40
  result = http.request(req).body
48
41
  JSON.parse result
49
- end
42
+ end
50
43
 
51
44
  # Send POST request
52
45
  def post(method, params = {})
@@ -54,9 +47,7 @@ class Onepagecrm
54
47
  req = Net::HTTP::Post.new(url.path)
55
48
  req.body = params.to_json
56
49
  req.add_field('Content-Type', 'application/json; charset=utf-8')
57
-
58
50
  add_auth_headers(req, 'POST', method, params)
59
-
60
51
  http = Net::HTTP.new(url.host, url.port)
61
52
  http.use_ssl = true
62
53
  result = http.request(req).body
@@ -70,30 +61,12 @@ class Onepagecrm
70
61
  req.body = params.to_json
71
62
  req.add_field('Content-Type', 'application/json; charset=utf-8')
72
63
  add_auth_headers(req, 'PUT', method, params)
73
-
74
64
  http = Net::HTTP.new(url.host, url.port)
75
65
  http.use_ssl = true
76
66
  result = http.request(req).body
77
67
  JSON.parse result
78
68
  end
79
69
 
80
- # Send DELETE request
81
- def delete(method, params = {})
82
- url = URI.parse(@url + method)
83
-
84
- delete_data = params.empty? ? '' : '?' + params.to_a.map do|x|
85
- x[0] + '=' +
86
- URI.escape(x[1], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
87
- end.join('&').gsub(/%[0-9A-Fa-f]{2}/) { |x| x.downcase }
88
-
89
- req = Net::HTTP::Delete.new(url.request_uri)
90
- add_auth_headers(req, 'DELETE', method, params)
91
- http = Net::HTTP.new(url.host, url.port)
92
- http.use_ssl = true
93
- result = http.request(req).body
94
- JSON.parse result
95
- end
96
-
97
70
  # Add authentication headers
98
71
  def add_auth_headers(req, http_method, api_method, params)
99
72
  return if @uid.nil? || @api_key.nil?
@@ -104,20 +77,20 @@ class Onepagecrm
104
77
 
105
78
  # puts url_to_sign
106
79
  timestamp = Time.now.to_i.to_s
107
-
108
- token = create_signature(@uid, @api_key, timestamp, http_method, url_to_sign, params)
80
+ token = create_token(timestamp, http_method, url_to_sign, params)
109
81
 
110
82
  req.add_field('X-OnePageCRM-UID', @uid)
111
83
  req.add_field('X-OnePageCRM-TS', timestamp)
112
84
  req.add_field('X-OnePageCRM-Auth', token)
113
85
  req.add_field('X-OnePageCRM-Source', 'lead_clip_chrome')
114
- end
86
+ end
115
87
 
116
- def create_signature(uid, api_key, timestamp, request_type, request_url, request_body)
88
+ # Creates the token for X-OnePageCRM-Auth
89
+ def create_token(timestamp, request_type, request_url, request_body)
117
90
  request_url_hash = Digest::SHA1.hexdigest request_url
118
91
  request_body_hash = Digest::SHA1.hexdigest request_body.to_json
119
- signature_message = [uid, timestamp, request_type.upcase, request_url_hash].join '.'
92
+ signature_message = [@uid, timestamp, request_type.upcase, request_url_hash].join '.'
120
93
  signature_message += ('.' + request_body_hash) unless request_body.empty?
121
- OpenSSL::HMAC.hexdigest('sha256', api_key, signature_message).to_s
94
+ OpenSSL::HMAC.hexdigest('sha256', @api_key, signature_message).to_s
122
95
  end
123
96
  end
@@ -1,3 +1,3 @@
1
1
  class Onepagecrm
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['peter@onepagecrm.com']
11
11
  spec.summary = %q{Basic Gem for OnePageCRM.}
12
12
  spec.description = %q{Basic Gem for OnePageCRM.}
13
- spec.homepage = ''
13
+ spec.homepage = 'http://developer.onepagecrm.com'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rspec'
24
24
  spec.add_development_dependency 'json_spec'
25
25
  spec.add_development_dependency 'codeclimate-test-reporter'
26
+ spec.add_development_dependency 'pry'
26
27
  end
@@ -1,11 +1,12 @@
1
1
  require 'spec_helper'
2
2
  require 'json_spec'
3
+ require 'pry'
3
4
 
4
5
  describe Onepagecrm do
5
6
  subject { Onepagecrm.new(TEST_CONFIG['login'], TEST_CONFIG['password']) }
6
7
 
7
- describe '#create_contact' do
8
- it 'creates a new contact' do
8
+ describe '#contact' do
9
+ it 'creates, gets, updates and deletes a contact' do
9
10
  new_contact_details = ({
10
11
  'first_name' => 'yes',
11
12
  'last_name' => 'address',
@@ -31,7 +32,7 @@ describe Onepagecrm do
31
32
 
32
33
  new_contact = subject.post('contacts.json', new_contact_details)['data']
33
34
  new_contact_id = new_contact['contact']['id']
34
- got_deets = subject.get("contacts/#{new_contact_id}.json")['data']['contact']
35
+ got_deets = subject.get("contacts/#{new_contact_id}.json?search=yes")['data']['contact']
35
36
  expect(got_deets['first_name']).to eq(new_contact_details['first_name'])
36
37
 
37
38
  details_without_address = new_contact_details.reject { |k| k == 'address_list' }
@@ -45,6 +46,11 @@ describe Onepagecrm do
45
46
  expect(address['city']).to eq 'San Francisco'
46
47
  expect(address['state']).to eq 'CA'
47
48
 
49
+ subject.put("contacts/#{new_contact_id}.json", { 'partial' => true,
50
+ 'first_name' => 'Pat' })
51
+ got_deets = subject.get("contacts/#{new_contact_id}.json")['data']['contact']
52
+ expect(got_deets['first_name']).to eq 'Pat'
53
+
48
54
  # delete contact
49
55
  subject.delete("contacts/#{new_contact_id}.json")
50
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onepagecrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Armstrong
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Basic Gem for OnePageCRM.
84
98
  email:
85
99
  - peter@onepagecrm.com
@@ -99,7 +113,7 @@ files:
99
113
  - spec/contacts_spec.rb
100
114
  - spec/spec_helper.rb
101
115
  - tasks/rspec.rake
102
- homepage: ''
116
+ homepage: http://developer.onepagecrm.com
103
117
  licenses:
104
118
  - MIT
105
119
  metadata: {}