onepagecrm 0.0.7 → 0.2.0

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
- SHA1:
3
- metadata.gz: 2859dfc423493ac5aef46f2dc87faa6601d44ccb
4
- data.tar.gz: d3f35388dec43c2472f12f99e9b91b418f872f38
2
+ SHA256:
3
+ metadata.gz: 6f43b8af18d61a41037c8f68194d03d919f7474f0dc22ddbf532c0821d52faa0
4
+ data.tar.gz: aaf2df2075abd43f72d288fe2e5e7018b7d9b41bd5e65c2f68a1cde3989292fc
5
5
  SHA512:
6
- metadata.gz: d9683174012ce7b0df6e3d76a81a445077910f244d762d14d8790904a6b8b92fe820acc274bf29f427e0256785d08b6e08e0120ece9057bf544ae824f2630699
7
- data.tar.gz: 8d399642d5a675af251c91e6615345e4ceaa719264c57b848ce5392622ca76956000826d2ad353fd337448fe392dc8766b1a322347af975ddfd942cbf76870f2
6
+ metadata.gz: 0db66e59769acc854b5a97004ab8f350294487b598ac08b2e53764ec1530910944011702d9a07dede643ef934a1ca7273901583c07adaac3cf06b71ba4d7b351
7
+ data.tar.gz: 57ea63f3882375254073ed092d6ebc55c7eacf2634be5da8490072506282d8e49abcc7fe522128fa231c00474e3a225323caa7ca41c2e0d7b0ed5b3d81345b05
data/.gitignore CHANGED
@@ -13,4 +13,5 @@
13
13
  *.a
14
14
  mkmf.log
15
15
  config.yml
16
+ .idea/
16
17
 
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in onepagecrm.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ # Better ruby interpreter
8
+ gem 'pry'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ onepagecrm (0.2.0)
5
+ faraday
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.3)
11
+ faraday (1.7.1)
12
+ faraday-em_http (~> 1.0)
13
+ faraday-em_synchrony (~> 1.0)
14
+ faraday-excon (~> 1.1)
15
+ faraday-httpclient (~> 1.0.1)
16
+ faraday-net_http (~> 1.0)
17
+ faraday-net_http_persistent (~> 1.1)
18
+ faraday-patron (~> 1.0)
19
+ faraday-rack (~> 1.0)
20
+ multipart-post (>= 1.2, < 3)
21
+ ruby2_keywords (>= 0.0.4)
22
+ faraday-em_http (1.0.0)
23
+ faraday-em_synchrony (1.0.0)
24
+ faraday-excon (1.1.0)
25
+ faraday-httpclient (1.0.1)
26
+ faraday-net_http (1.0.1)
27
+ faraday-net_http_persistent (1.2.0)
28
+ faraday-patron (1.0.0)
29
+ faraday-rack (1.0.0)
30
+ method_source (1.0.0)
31
+ multipart-post (2.1.1)
32
+ pry (0.14.1)
33
+ coderay (~> 1.1)
34
+ method_source (~> 1.0)
35
+ rake (10.5.0)
36
+ ruby2_keywords (0.0.5)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 2.2.18)
43
+ onepagecrm!
44
+ pry
45
+ rake (~> 10.5)
46
+
47
+ BUNDLED WITH
48
+ 2.2.18
data/README.md CHANGED
@@ -1,18 +1,14 @@
1
- [![Code Climate](https://codeclimate.com/github/peterOnePageCRM/onepagecrm-gem/badges/gpa.svg)](https://codeclimate.com/github/peterOnePageCRM/onepagecrm-gem)
1
+ # OnePageCRM
2
2
 
3
- [![Test Coverage](https://codeclimate.com/github/peterOnePageCRM/onepagecrm-gem/badges/coverage.svg)](https://codeclimate.com/github/peterOnePageCRM/onepagecrm-gem)
4
-
5
- # Onepagecrm
6
-
7
- TODO: Write a gem description
3
+ This gem is a basic wrapper around the OnePageCRM API.
4
+ It does not abstract all API calls to ruby methods on the gem object but simply gives the `GET`, `POST`, `PUT` and `DELETE` methods.
5
+ The gem handles all the authentication with the OnePageCRM API.
8
6
 
9
7
  ## Installation
10
8
 
11
9
  Add this line to your application's Gemfile:
12
10
 
13
- ```ruby
14
- gem 'onepagecrm'
15
- ```
11
+ gem 'onepagecrm'
16
12
 
17
13
  And then execute:
18
14
 
@@ -23,13 +19,29 @@ Or install it yourself as:
23
19
  $ gem install onepagecrm
24
20
 
25
21
  ## Usage
22
+ You can try out the OnePageCRM gem in an interactive ruby session
23
+
24
+ $ irb
25
+ irb:> require 'onepagecrm'
26
+ irb:> api_client = OnePageCRM.new('user_id', 'api_key')
27
+ irb:> api_client.get('contacts.json')
28
+ irb:> api_client.post('contacts.json', {'last_name': 'Bravo', 'first_name': 'Johnny'} )
29
+
30
+ Take a look at the [OnePageCRM Developer][1] site for more details on API functionality.
26
31
 
27
- TODO: Write usage instructions here
32
+ ## Support
33
+ The best way to get support is through the [OnePageCRM Developer Forum][2]
28
34
 
29
35
  ## Contributing
30
36
 
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
37
+ We welcome any contributions.
38
+
39
+ 1. Create an issue relating to the feature that you require.
40
+ 2. Fork the repo ( https://github.com/[my-github-username]/onepagecrm/fork )
41
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 5. Push to the branch (`git push origin my-new-feature`)
44
+ 6. Create a new Pull Request
45
+
46
+ [1]: http://developer.onepagecrm.com
47
+ [2]: http://forum.developer.onepagecrm.com
@@ -1,3 +1,4 @@
1
- class Onepagecrm
2
- VERSION = '0.0.7'
1
+ # Version for OnePageCRM gem
2
+ class OnePageCRM
3
+ VERSION = '0.2.0'
3
4
  end
data/lib/onepagecrm.rb CHANGED
@@ -1,123 +1,36 @@
1
1
  require 'onepagecrm/version'
2
- require 'net/http'
3
- require 'openssl'
4
2
  require 'base64'
5
3
  require 'json'
6
- require 'uri'
7
-
8
- class Onepagecrm
9
- def initialize(login = nil, password = nil)
10
- @url = 'https://app.onepagecrm.com/api/v3/'
11
- @login = login
12
- @password = password
13
- log_in
14
- end
15
-
16
- # Login user into API
17
- def log_in
18
- params = {
19
- login: @login,
20
- password: @password
21
- }
22
-
23
- auth_data = post('login.json', params)
24
- @uid = auth_data['data']['user_id']
25
-
26
- @api_key = Base64.decode64(auth_data['data']['auth_key'])
27
- end
28
-
29
- def return_uid
30
- @uid
31
- end
32
-
33
- # Send GET request
34
- def get(method, params = {})
35
- 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
- req = Net::HTTP::Get.new(url.request_uri)
42
-
43
- add_auth_headers(req, 'GET', method, params)
44
-
45
- http = Net::HTTP.new(url.host, url.port)
46
- http.use_ssl = true
47
- result = http.request(req).body
48
- JSON.parse result
4
+ require 'faraday'
5
+
6
+ # OnePageCRM API Client Object
7
+ class OnePageCRM
8
+ def initialize(user_id, api_key)
9
+ url = 'https://app.onepagecrm.com/api/v3/'
10
+ @conn = Faraday.new(url: url) do |conn|
11
+ conn.adapter Faraday.default_adapter
12
+ conn.basic_auth(user_id, api_key)
13
+ conn.headers.merge!(
14
+ 'Content-Type' => 'application/json',
15
+ 'X-OnePageCRM-UID' => user_id,
16
+ 'X-OnePageCRM-Source' => 'ruby_gem'
17
+ )
49
18
  end
50
-
51
- # Send POST request
52
- def post(method, params = {})
53
- url = URI.parse(@url + method)
54
- req = Net::HTTP::Post.new(url.path)
55
- req.body = params.to_json
56
- req.add_field('Content-Type', 'application/json; charset=utf-8')
57
-
58
- add_auth_headers(req, 'POST', method, params)
59
-
60
- http = Net::HTTP.new(url.host, url.port)
61
- http.use_ssl = true
62
- result = http.request(req).body
63
- JSON.parse result
64
19
  end
65
20
 
66
- # Send PUT request
67
- def put(method, params = {})
68
- url = URI.parse(@url + method)
69
- req = Net::HTTP::Put.new(url.path)
70
- req.body = params.to_json
71
- req.add_field('Content-Type', 'application/json; charset=utf-8')
72
- add_auth_headers(req, 'PUT', method, params)
73
-
74
- http = Net::HTTP.new(url.host, url.port)
75
- http.use_ssl = true
76
- result = http.request(req).body
77
- JSON.parse result
21
+ # defines get and delete methods
22
+ %w(get delete).each do |http_method|
23
+ define_method http_method do |endpoint, params = {}|
24
+ response = @conn.send(http_method, endpoint, params)
25
+ JSON.parse response.body
26
+ end
78
27
  end
79
28
 
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
29
+ # Defines put and post methods
30
+ %w(post put).each do |http_method|
31
+ define_method http_method do |endpoint, params = {}|
32
+ response = @conn.send(http_method, endpoint, params.to_json)
33
+ JSON.parse response.body
95
34
  end
96
-
97
- # Add authentication headers
98
- def add_auth_headers(req, http_method, api_method, params)
99
- return if @uid.nil? || @api_key.nil?
100
-
101
- url_to_sign = @url + api_method
102
- params_to_sign = params.empty? ? nil : URI.encode_www_form(params)
103
- url_to_sign += '?' + params_to_sign unless params_to_sign.nil? || %w(POST PUT).include?(http_method)
104
-
105
- # puts url_to_sign
106
- timestamp = Time.now.to_i.to_s
107
-
108
- token = create_signature(@uid, @api_key, timestamp, http_method, url_to_sign, params)
109
-
110
- req.add_field('X-OnePageCRM-UID', @uid)
111
- req.add_field('X-OnePageCRM-TS', timestamp)
112
- req.add_field('X-OnePageCRM-Auth', token)
113
- req.add_field('X-OnePageCRM-Source', 'lead_clip_chrome')
114
- end
115
-
116
- def create_signature(uid, api_key, timestamp, request_type, request_url, request_body)
117
- request_url_hash = Digest::SHA1.hexdigest request_url
118
- request_body_hash = Digest::SHA1.hexdigest request_body.to_json
119
- signature_message = [uid, timestamp, request_type.upcase, request_url_hash].join '.'
120
- signature_message += ('.' + request_body_hash) unless request_body.empty?
121
- OpenSSL::HMAC.hexdigest('sha256', api_key, signature_message).to_s
122
35
  end
123
36
  end
data/onepagecrm.gemspec CHANGED
@@ -2,25 +2,22 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'onepagecrm/version'
5
-
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = 'onepagecrm'
8
- spec.version = Onepagecrm::VERSION
7
+ spec.version = OnePageCRM::VERSION
9
8
  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 = ''
9
+ spec.email = ['devteam@onepagecrm.com']
10
+ spec.summary = 'Basic Gem for OnePageCRM'
11
+ spec.description = 'Basic Gem for the OnePageCRM API'
12
+ spec.homepage = 'http://developer.onepagecrm.com'
14
13
  spec.license = 'MIT'
15
-
16
14
  spec.files = `git ls-files -z`.split("\x0")
17
15
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
17
  spec.require_paths = ['lib']
20
18
 
21
- spec.add_development_dependency 'bundler', '~> 1.7'
22
- spec.add_development_dependency 'rake', '~> 10.0'
23
- spec.add_development_dependency 'rspec'
24
- spec.add_development_dependency 'json_spec'
25
- spec.add_development_dependency 'codeclimate-test-reporter'
19
+ spec.add_dependency 'faraday'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 2.2.18'
22
+ spec.add_development_dependency 'rake', '~> 10.5'
26
23
  end
metadata CHANGED
@@ -1,51 +1,23 @@
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Armstrong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-22 00:00:00.000000000 Z
11
+ date: 2021-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
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
14
+ name: faraday
43
15
  requirement: !ruby/object:Gem::Requirement
44
16
  requirements:
45
17
  - - ">="
46
18
  - !ruby/object:Gem::Version
47
19
  version: '0'
48
- type: :development
20
+ type: :runtime
49
21
  prerelease: false
50
22
  version_requirements: !ruby/object:Gem::Requirement
51
23
  requirements:
@@ -53,53 +25,50 @@ dependencies:
53
25
  - !ruby/object:Gem::Version
54
26
  version: '0'
55
27
  - !ruby/object:Gem::Dependency
56
- name: json_spec
28
+ name: bundler
57
29
  requirement: !ruby/object:Gem::Requirement
58
30
  requirements:
59
- - - ">="
31
+ - - "~>"
60
32
  - !ruby/object:Gem::Version
61
- version: '0'
33
+ version: 2.2.18
62
34
  type: :development
63
35
  prerelease: false
64
36
  version_requirements: !ruby/object:Gem::Requirement
65
37
  requirements:
66
- - - ">="
38
+ - - "~>"
67
39
  - !ruby/object:Gem::Version
68
- version: '0'
40
+ version: 2.2.18
69
41
  - !ruby/object:Gem::Dependency
70
- name: codeclimate-test-reporter
42
+ name: rake
71
43
  requirement: !ruby/object:Gem::Requirement
72
44
  requirements:
73
- - - ">="
45
+ - - "~>"
74
46
  - !ruby/object:Gem::Version
75
- version: '0'
47
+ version: '10.5'
76
48
  type: :development
77
49
  prerelease: false
78
50
  version_requirements: !ruby/object:Gem::Requirement
79
51
  requirements:
80
- - - ">="
52
+ - - "~>"
81
53
  - !ruby/object:Gem::Version
82
- version: '0'
83
- description: Basic Gem for OnePageCRM.
54
+ version: '10.5'
55
+ description: Basic Gem for the OnePageCRM API
84
56
  email:
85
- - peter@onepagecrm.com
57
+ - devteam@onepagecrm.com
86
58
  executables: []
87
59
  extensions: []
88
60
  extra_rdoc_files: []
89
61
  files:
90
62
  - ".gitignore"
91
63
  - Gemfile
64
+ - Gemfile.lock
92
65
  - LICENSE.txt
93
66
  - README.md
94
67
  - Rakefile
95
- - config/config_orig.yml
96
68
  - lib/onepagecrm.rb
97
69
  - lib/onepagecrm/version.rb
98
70
  - onepagecrm.gemspec
99
- - spec/contacts_spec.rb
100
- - spec/spec_helper.rb
101
- - tasks/rspec.rake
102
- homepage: ''
71
+ homepage: http://developer.onepagecrm.com
103
72
  licenses:
104
73
  - MIT
105
74
  metadata: {}
@@ -118,11 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
87
  - !ruby/object:Gem::Version
119
88
  version: '0'
120
89
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.2.2
90
+ rubygems_version: 3.1.6
123
91
  signing_key:
124
92
  specification_version: 4
125
- summary: Basic Gem for OnePageCRM.
126
- test_files:
127
- - spec/contacts_spec.rb
128
- - spec/spec_helper.rb
93
+ summary: Basic Gem for OnePageCRM
94
+ test_files: []
@@ -1,2 +0,0 @@
1
- login: "login@example.com"
2
- password: "Password?Goes?Here?Ok?"
@@ -1,53 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
1
- require 'yaml'
2
- require 'codeclimate-test-reporter'
3
- TEST_CONFIG = YAML.load_file("#{File.dirname(__FILE__)}/../config/config.yml")
4
-
5
- ENV['CODECLIMATE_REPO_TOKEN'] = TEST_CONFIG['codeclimate_key']
6
- CodeClimate::TestReporter.start
7
- require 'onepagecrm'
data/tasks/rspec.rake DELETED
@@ -1,3 +0,0 @@
1
- require 'rspec/core/rake_task'
2
-
3
- RSpec::Core::RakeTask.new(:spec)