pocus 0.6.1 → 1.0.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 +4 -4
- data/README.md +17 -5
- data/lib/pocus/account.rb +2 -0
- data/lib/pocus/association.rb +4 -0
- data/lib/pocus/client_folder.rb +0 -1
- data/lib/pocus/identity.rb +1 -1
- data/lib/pocus/resource.rb +1 -1
- data/lib/pocus/session.rb +13 -11
- metadata +3 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02c9225454a2501e4a0e0defeb658efab6e98605af4992a5304eed799e29b10e
|
4
|
+
data.tar.gz: 427a91c96bfc410c107ba17cabc7b0e96307b56fa655f4b463e03ac39e8a4a3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
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
|
data/lib/pocus/account.rb
CHANGED
data/lib/pocus/association.rb
CHANGED
data/lib/pocus/client_folder.rb
CHANGED
data/lib/pocus/identity.rb
CHANGED
data/lib/pocus/resource.rb
CHANGED
data/lib/pocus/session.rb
CHANGED
@@ -16,11 +16,12 @@ module Pocus
|
|
16
16
|
|
17
17
|
# Sends authenticated JSON requests to remote service using HTTPS.
|
18
18
|
class Session
|
19
|
-
|
19
|
+
attr_reader :base_url
|
20
20
|
attr_reader :credentials
|
21
21
|
attr_accessor :logger
|
22
22
|
|
23
|
-
def initialize(
|
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
|
-
|
33
|
-
|
34
|
-
|
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(
|
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
|
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
|
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.
|
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-
|
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
|
-
|
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
|