trogdir_api_client 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: c84869f5c27f1d6ff0e6b6c542f0066bf0c41fd5
4
- data.tar.gz: 5140f152412bf8030873d74c07b54408b318f18c
3
+ metadata.gz: ea9c3e595f525942487a98181287f1c6ed41c6ad
4
+ data.tar.gz: f6e92275bd78dcaa4a273419af082f4d7a0feb77
5
5
  SHA512:
6
- metadata.gz: b3f7af1b5cb00fb77e0e9cf1f4a4a2b9efc8ee254248423357f17956c1c8d5a71da35fd39560fcbab9c76a0120499d6a538aacf27c1f22f3aa01b7dbf678a7a1
7
- data.tar.gz: 6878a454c3674445e8fd68326bb78a8f1c70400312e6276fd376e0990472a6b267c960a5f9b98311e56eb94c4b2c839cc347f1df6971beacf0736da9fa23a756
6
+ metadata.gz: c3aece16e1db4297f4e434c2494995e3d9202e17a5ec619b64ab3704705bf092a2c3151929ba9c28d639dc30f224832a4ec17497f7c6087d3afaa8d0ac44f914
7
+ data.tar.gz: 61e17953d264e2f47149750274ef0dfec6ae15438977805805f124b1c6c4c54000567ab8634616ace80238ae2261c2be4f28107d0eeada4b3b22574d72b400d5
data/README.md CHANGED
@@ -6,10 +6,89 @@ Installing
6
6
 
7
7
  Add `gem 'trogdir_api_client'` to your `Gemfile` and run `bundle`
8
8
 
9
+ Configuration
10
+ -------------
11
+
12
+ ```ruby
13
+ TrogdirAPIClient.configure do |config|
14
+ # Optional:
15
+ # config.scheme = 'http'
16
+ # config.host = 'localhost'
17
+ # config.script_name = nil
18
+ # config.version = 'v1'
19
+
20
+ # Required:
21
+ config.access_id = '**************'
22
+ config.secret_key = '*****************************************'
23
+ end
24
+ ```
25
+
9
26
  Usage
10
27
  -----
11
28
 
12
- TODO
29
+ ### Example Syncinator
30
+
31
+ ```ruby
32
+ require 'trogdir_api_client'
33
+ require 'multi_json'
34
+
35
+ trogdir = Trogdir::APIClient::ChangeSyncs.new
36
+ hashes = trogdir.start.perform.parse
37
+
38
+ hashes.each do |hash|
39
+ sync_log_id = hash['sync_log_id']
40
+ action = hash['action']
41
+ person_id = hash['person_id']
42
+ scope = hash['scope']
43
+ original = hash['original']
44
+ modified = hash['modified']
45
+
46
+ action_taken = 'nothing'
47
+
48
+ begin
49
+ person = Person.find(person_id)
50
+
51
+ case scope
52
+ when 'person'
53
+ case action
54
+ when 'create'
55
+ # do stuff
56
+ action_taken = 'create'
57
+ when 'update'
58
+ # do stuff
59
+ action_taken = 'update'
60
+ when 'destroy'
61
+ # do stuff
62
+ action_taken = 'destroy'
63
+ end
64
+ when 'id'
65
+ case action
66
+ when 'create'
67
+ # do stuff
68
+ action_taken = 'create'
69
+ when 'update'
70
+ # do stuff
71
+ action_taken = 'update'
72
+ when 'destroy'
73
+ # do stuff
74
+ action_taken = 'destroy'
75
+ end
76
+ when 'email'
77
+ # blah
78
+ when 'photo'
79
+ # blah
80
+ when 'phone'
81
+ # blah
82
+ when 'address'
83
+ # blah
84
+ end
85
+
86
+ trogdir.finish(sync_log_id: sync_log_id, action: action_taken).perform
87
+ rescue StandardError => err
88
+ trogdir.error(sync_log_id: sync_log_id, message: err.message).perform
89
+ end
90
+ end
91
+ ```
13
92
 
14
93
  License
15
94
  -------
@@ -1,8 +1,7 @@
1
1
  module Trogdir
2
2
  module APIClient
3
3
  class Addresses < Weary::Client
4
- domain TrogdirAPIClient.config.base_url
5
- use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
4
+ include Settings
6
5
 
7
6
  get :index, '/people/{uuid}/addresses'
8
7
 
@@ -20,4 +19,4 @@ module Trogdir
20
19
  delete :destroy, '/people/{uuid}/addresses/{address_id}'
21
20
  end
22
21
  end
23
- end
22
+ end
@@ -1,8 +1,7 @@
1
1
  module Trogdir
2
2
  module APIClient
3
3
  class ChangeSyncs < Weary::Client
4
- domain TrogdirAPIClient.config.base_url
5
- use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
4
+ include Settings
6
5
 
7
6
  put :start, '/change_syncs/start'
8
7
 
@@ -16,4 +15,4 @@ module Trogdir
16
15
  end
17
16
  end
18
17
  end
19
- end
18
+ end
@@ -1,8 +1,7 @@
1
1
  module Trogdir
2
2
  module APIClient
3
3
  class Emails < Weary::Client
4
- domain TrogdirAPIClient.config.base_url
5
- use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
4
+ include Settings
6
5
 
7
6
  get :index, '/people/{uuid}/emails'
8
7
 
@@ -20,4 +19,4 @@ module Trogdir
20
19
  delete :destroy, '/people/{uuid}/emails/{email_id}'
21
20
  end
22
21
  end
23
- end
22
+ end
@@ -1,9 +1,7 @@
1
1
  module Trogdir
2
2
  module APIClient
3
3
  class IDs < Weary::Client
4
- domain TrogdirAPIClient.config.base_url
5
- # use Weary::Middleware::ContentType
6
- use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
4
+ include Settings
7
5
 
8
6
  get :index, '/people/{uuid}/ids'
9
7
 
@@ -20,4 +18,4 @@ module Trogdir
20
18
  delete :destroy, '/people/{uuid}/ids/{id_id}'
21
19
  end
22
20
  end
23
- end
21
+ end
@@ -1,9 +1,7 @@
1
1
  module Trogdir
2
2
  module APIClient
3
3
  class People < Weary::Client
4
- domain TrogdirAPIClient.config.base_url
5
- # use Weary::Middleware::ContentType
6
- use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
4
+ include Settings
7
5
 
8
6
  get :index, '/people' do |resource|
9
7
  resource.optional :affiliation
@@ -49,4 +47,4 @@ module Trogdir
49
47
  end
50
48
  end
51
49
  end
52
- end
50
+ end
@@ -1,8 +1,7 @@
1
1
  module Trogdir
2
2
  module APIClient
3
3
  class Phones < Weary::Client
4
- domain TrogdirAPIClient.config.base_url
5
- use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
4
+ include Settings
6
5
 
7
6
  get :index, '/people/{uuid}/phones'
8
7
 
@@ -20,4 +19,4 @@ module Trogdir
20
19
  delete :destroy, '/people/{uuid}/phones/{phone_id}'
21
20
  end
22
21
  end
23
- end
22
+ end
@@ -1,8 +1,7 @@
1
1
  module Trogdir
2
2
  module APIClient
3
3
  class Photos < Weary::Client
4
- domain TrogdirAPIClient.config.base_url
5
- use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
4
+ include Settings
6
5
 
7
6
  get :index, '/people/{uuid}/photos'
8
7
 
@@ -19,4 +18,4 @@ module Trogdir
19
18
  delete :destroy, '/people/{uuid}/photos/{photo_id}'
20
19
  end
21
20
  end
22
- end
21
+ end
@@ -0,0 +1,11 @@
1
+ module Trogdir
2
+ module APIClient
3
+ module Settings
4
+ def self.included(base)
5
+ base.send :domain, TrogdirAPIClient.config.base_url
6
+ base.send :adapter, Weary::Adapter::NetHttpAdvanced
7
+ base.send :use, Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -14,6 +14,7 @@ end
14
14
 
15
15
  module Trogdir
16
16
  module APIClient
17
+ autoload :Settings, 'trogdir/api_client/settings'
17
18
  autoload :People, 'trogdir/api_client/people'
18
19
  autoload :IDs, 'trogdir/api_client/ids'
19
20
  autoload :Emails, 'trogdir/api_client/emails'
@@ -28,4 +29,8 @@ module Weary
28
29
  module Middleware
29
30
  autoload :HMACAuth, 'weary/middleware/hmac_auth'
30
31
  end
31
- end
32
+
33
+ module Adapter
34
+ autoload :NetHttpAdvanced, 'weary/adapters/net_http_advanced'
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module TrogdirAPIClient
2
- VERSION = '0.1.0'
3
- end
2
+ VERSION = '0.2.0'
3
+ end
@@ -0,0 +1,16 @@
1
+ module Weary
2
+ module Adapter
3
+ class NetHttpAdvanced < NetHttp
4
+ class << self
5
+ attr_accessor :timeout
6
+ end
7
+
8
+ def self.connect(request)
9
+ connection = socket(request)
10
+ connection.read_timeout = timeout unless timeout.nil?
11
+ response = connection.request prepare(request)
12
+ Rack::Response.new response.body || "", response.code, normalize_response(response.to_hash)
13
+ end
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trogdir_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api-auth
@@ -151,9 +151,11 @@ files:
151
151
  - lib/trogdir/api_client/people.rb
152
152
  - lib/trogdir/api_client/phones.rb
153
153
  - lib/trogdir/api_client/photos.rb
154
+ - lib/trogdir/api_client/settings.rb
154
155
  - lib/trogdir_api_client.rb
155
156
  - lib/trogdir_api_client/configuration.rb
156
157
  - lib/trogdir_api_client/version.rb
158
+ - lib/weary/adapters/net_http_advanced.rb
157
159
  - lib/weary/middleware/hmac_auth.rb
158
160
  homepage: https://github.com/biola/trogdir-api-client
159
161
  licenses:
@@ -180,3 +182,4 @@ signing_key:
180
182
  specification_version: 4
181
183
  summary: Client for the Trogdir directory API
182
184
  test_files: []
185
+ has_rdoc: