pocus 0.6.1 → 1.0.0

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
  SHA256:
3
- metadata.gz: dd0d631d3b8cf6ef526d738b4d4072a6bb9828fe9752d08df511cd0643278d7d
4
- data.tar.gz: 31e2a7de81869a442640f053057dad727052004fb2e2d61f24b085ae73161a4c
3
+ metadata.gz: 02c9225454a2501e4a0e0defeb658efab6e98605af4992a5304eed799e29b10e
4
+ data.tar.gz: 427a91c96bfc410c107ba17cabc7b0e96307b56fa655f4b463e03ac39e8a4a3d
5
5
  SHA512:
6
- metadata.gz: c22999094d8d036434a0b03ed2505e9a1a9fc2eb8b17aec0d8dd81320658518e3ce978079bd40df187b9da5ddd0aef8d7e68b8a49c3f9cf92cd8a2c7f9525200
7
- data.tar.gz: 7d113e2c3d7e511de3086a7c167a6e8d702d01af4d193a505547c5beae9b34df128c6a1a1b9a0eeada70729846709722ec572473afad9d3a339752ebd4de27dc
6
+ metadata.gz: 527b43fc28027052bc70ca44118d7276f0b736c819abeaf99eb3e73aa9e6fec1d974c0f86fa0e711cc25616642d677af479df363f99827011aa765f2a36efbfe
7
+ data.tar.gz: 59b882592a4d9053cc1f80782a6fde301653e979a76083912a9b07edba13935009053d0c1740da3855899609c18c8ab4de7095477ed55e0d7619f6d50ab5f2c9
data/README.md CHANGED
@@ -18,21 +18,33 @@ And then execute:
18
18
 
19
19
  $ bundle
20
20
 
21
+ ## Requirements
22
+
23
+ iContact account, AppID and credentials, see the [iContact API Getting Started Guide](https://www.icontact.com/developerportal/documentation/start-building).
24
+
21
25
  ## Usage
22
26
 
23
- Example:
27
+ Configure a connection and connect to the account:
24
28
 
29
+ ```ruby
30
+ credentials = { host: 'app.icontact.com', app_id: a, username: u, password: p }
31
+ session = Pocus::Session.new(credentials)
32
+ session.logger = Rails.logger
33
+ account = Pocus::Account.new(session: session, account_id: account_id)
25
34
  ```
26
- Pocus::Session.config(credentials)
27
- Pocus::Session.instance.logger = Rails.logger
28
- account = Pocus::Account.new(account_id: account_id)
35
+
36
+ Navigate and update entities:
37
+
38
+ ```ruby
29
39
  folder = acount.clientfolders.find(folder_id)
30
40
  folder.contacts.create(contacts_data)
31
41
  ```
32
42
 
43
+ See the specs for sample code.
44
+
33
45
  ## Tests
34
46
 
35
- To run the tests you will need your own iContact account with a test folder. Set the following environment variables:
47
+ To run the tests you will need your own iContact account with a test folder (name: 'My First List'). Set the following environment variables:
36
48
 
37
49
  ```
38
50
  POCUS_APP_ID=0b34...b478c
@@ -3,6 +3,8 @@ module Pocus
3
3
  self.path = :a
4
4
  self.primary_key = :account_id
5
5
 
6
+ attr_accessor :session
6
7
  has_many :clientfolders, path: '/c', class: 'ClientFolder'
8
+ has_many :users, class: 'User'
7
9
  end
8
10
  end
@@ -28,6 +28,10 @@ module Pocus
28
28
  owner.get("#{path}/#{id}", klass)
29
29
  end
30
30
 
31
+ def find_or_create_by(attributes)
32
+ where(attributes).first || create(attributes)
33
+ end
34
+
31
35
  def where(filters)
32
36
  owner.get_multiple(path, klass, filters)
33
37
  end
@@ -9,6 +9,5 @@ module Pocus
9
9
  has_many :customfields, class: 'CustomField'
10
10
  has_many :segments, class: 'Segment'
11
11
  has_many :subscriptions, class: 'Subscription'
12
- has_many :users, class: 'User'
13
12
  end
14
13
  end
@@ -12,7 +12,7 @@ module Pocus
12
12
  end
13
13
 
14
14
  def self.version
15
- '0.6.1'
15
+ '1.0.0'
16
16
  end
17
17
 
18
18
  def self.version_label
@@ -119,7 +119,7 @@ module Pocus
119
119
  end
120
120
 
121
121
  def session
122
- Session.instance
122
+ parent.session
123
123
  end
124
124
 
125
125
  def marshal_dump
@@ -16,11 +16,12 @@ module Pocus
16
16
 
17
17
  # Sends authenticated JSON requests to remote service using HTTPS.
18
18
  class Session
19
- BASE_URL = 'https://api.invoc.us/icp'.freeze
19
+ attr_reader :base_url
20
20
  attr_reader :credentials
21
21
  attr_accessor :logger
22
22
 
23
- def initialize(app_id: '', username: '', password: '', logger: Logger.new('/dev/null'))
23
+ def initialize(host: 'api.invoc.us', app_id:, username:, password:, logger: Logger.new('/dev/null'))
24
+ @base_url = "https://#{host}/icp".freeze
24
25
  @credentials = {
25
26
  'API-AppId' => app_id,
26
27
  'API-Username' => username,
@@ -29,18 +30,15 @@ module Pocus
29
30
  @logger = logger
30
31
  end
31
32
 
32
- def self.config(options = {})
33
- @config = options
34
- end
35
-
36
- def self.instance
37
- @instance ||= new(@config)
33
+ # 'Pro' is legacy as moniker dropped.
34
+ def pro?
35
+ base_url =~ /invoc.us/
38
36
  end
39
37
 
40
38
  # Accepts hash of fields to send.
41
39
  # Returns parsed response body, always a hash.
42
40
  def send_request(method, path, fields = {})
43
- response = send_logged_request(URI(BASE_URL + path), method, request_data(fields))
41
+ response = send_logged_request(URI(base_url + path), method, request_data(fields))
44
42
  fail UnexpectedHttpResponse, response unless response.is_a? Net::HTTPSuccess
45
43
  JSON.parse(response.body)
46
44
  end
@@ -69,13 +67,17 @@ module Pocus
69
67
  end
70
68
 
71
69
  def log_request_response(uri, method, data)
72
- logger.info "request = #{method} #{uri}#{data ? '?' + data : ''}"
70
+ logger.info "[#{self.class.name}] request = #{method} #{uri}#{data ? '?' + data : ''}"
73
71
  response = nil
74
72
  tms = Benchmark.measure do
75
73
  response = yield uri, method, data
76
74
  end
77
- logger.info("API response (#{tms.real}s): #{response.inspect} #{response.body}")
75
+ logger.info "[#{self.class.name}] response (#{ms(tms)}ms): #{response.inspect} #{response.body}"
78
76
  response
79
77
  end
78
+
79
+ def ms(tms)
80
+ (tms.real*1000).round(3)
81
+ end
80
82
  end
81
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pocus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piers Chambers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-21 00:00:00.000000000 Z
11
+ date: 2019-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: pry-byebug
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
41
  - !ruby/object:Gem::Dependency
56
42
  name: pry-state
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -127,8 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
113
  - !ruby/object:Gem::Version
128
114
  version: '0'
129
115
  requirements: []
130
- rubyforge_project:
131
- rubygems_version: 2.7.7
116
+ rubygems_version: 3.0.3
132
117
  signing_key:
133
118
  specification_version: 4
134
119
  summary: Unofficial Ruby client for iContact API