orchestrate 0.5.1 → 0.6.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.
@@ -0,0 +1,36 @@
1
+ require_relative '../../test_helper'
2
+
3
+ class ResponseTest < MiniTest::Unit::TestCase
4
+
5
+ def setup
6
+ @client, @stubs, @basic_auth = make_client_and_artifacts
7
+ end
8
+
9
+ def test_collection_with_next_prev_link
10
+ @stubs.get("/v0/things") do |env|
11
+ assert_authorization @basic_auth, env
12
+ case env.params['offset']
13
+ when nil, '0'
14
+ nextLink = "/v0/things?offset=10"
15
+ [ 200, response_headers, { count: 14, next: nextLink, results: [] }.to_json ]
16
+ when '10'
17
+ prevLink = "/v0/things?offset=0"
18
+ [ 200, response_headers, { count: 14, prev: prevLink, results: [] }.to_json ]
19
+ else
20
+ [ 404, response_headers, '{}' ]
21
+ end
22
+ end
23
+ response = @client.list(:things)
24
+ assert response.next_link
25
+
26
+ next_page = response.next_results
27
+ assert_equal 200, next_page.status
28
+ assert_equal 14, next_page.count
29
+ assert_nil next_page.next_results
30
+
31
+ previous_page = next_page.previous_results
32
+ assert_equal 200, previous_page.status
33
+ assert_equal 14, previous_page.count
34
+ assert_nil previous_page.previous_results
35
+ end
36
+ end
@@ -3,32 +3,23 @@ require "test_helper"
3
3
  describe Orchestrate::Client do
4
4
 
5
5
  it "should initialize" do
6
- client = Orchestrate::Client.new
6
+ client = Orchestrate::Client.new('8c3')
7
7
  client.must_be_kind_of Orchestrate::Client
8
-
9
- client.config.must_equal Orchestrate.config
10
- end
11
-
12
- it "should initialize with config" do
13
- config = Orchestrate::Configuration.new(api_key: "test-api-key")
14
- client = Orchestrate::Client.new(config)
15
- client.must_be_kind_of Orchestrate::Client
16
- client.config.must_equal config
17
8
  end
18
9
 
19
10
  it "handles parallel requests" do
20
- @client, @stubs = make_client_and_artifacts
21
- @stubs.get("/v0/foo") do |env|
11
+ client, stubs = make_client_and_artifacts
12
+ stubs.get("/v0/foo") do |env|
22
13
  [ 200, response_headers, {}.to_json ]
23
14
  end
24
- @stubs.get("/v0/users/mattly") do |env|
15
+ stubs.get("/v0/users/mattly") do |env|
25
16
  [ 200, response_headers, {}.to_json ]
26
17
  end
27
18
  responses = nil
28
19
  capture_warnings do
29
- responses = @client.in_parallel do |r|
30
- r[:list] = @client.list(:foo)
31
- r[:user] = @client.get(:users, "mattly")
20
+ responses = client.in_parallel do |r|
21
+ r[:list] = client.list(:foo)
22
+ r[:user] = client.get(:users, "mattly")
32
23
  end
33
24
  end
34
25
  assert responses[:list]
@@ -37,4 +28,12 @@ describe Orchestrate::Client do
37
28
  assert_equal 200, responses[:user].status
38
29
  end
39
30
 
31
+ it "handles ping request" do
32
+ client, stubs = make_client_and_artifacts
33
+ stubs.get("/v0") do |env|
34
+ [ 200, response_headers, '' ]
35
+ end
36
+ client.ping
37
+ end
38
+
40
39
  end
data/test/test_helper.rb CHANGED
@@ -5,12 +5,12 @@ require "base64"
5
5
  require "faraday"
6
6
  require "securerandom"
7
7
  require "time"
8
+ require "logger"
8
9
 
9
10
  # Test Helpers ---------------------------------------------------------------
10
11
 
11
12
  def output_message(name, msg = nil)
12
13
  msg ||= "START TEST"
13
- Orchestrate.config.logger.debug "\n======= #{msg}: #{name} ======="
14
14
  end
15
15
 
16
16
  # TODO this is a bit messy for now at least but there's a bunch of
@@ -19,15 +19,10 @@ def make_client_and_artifacts
19
19
  api_key = SecureRandom.hex(24)
20
20
  basic_auth = "Basic #{Base64.encode64("#{api_key}:").gsub(/\n/,'')}"
21
21
  stubs = Faraday::Adapter::Test::Stubs.new
22
- # TODO: make it such that the client passes its optional config to the API::Request class
23
- Orchestrate.configure do |config|
24
- config.faraday = lambda do |faraday|
25
- faraday.adapter :test, stubs
26
- end
27
- config.api_key = api_key
28
- config.logger = Logger.new(File.join(File.dirname(__FILE__), "test.log"))
22
+ client = Orchestrate::Client.new(api_key) do |f|
23
+ f.adapter :test, stubs
24
+ f.response :logger, Logger.new(File.join(File.dirname(__FILE__), "test.log"))
29
25
  end
30
- client = Orchestrate::Client.new
31
26
  [client, stubs, basic_auth]
32
27
  end
33
28
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orchestrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Lyon
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-05-29 00:00:00.000000000 Z
13
+ date: 2014-06-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -127,6 +127,7 @@ extra_rdoc_files: []
127
127
  files:
128
128
  - ".gitignore"
129
129
  - ".travis.yml"
130
+ - ".yardopts"
130
131
  - Gemfile
131
132
  - LICENSE
132
133
  - README.md
@@ -134,17 +135,18 @@ files:
134
135
  - lib/orchestrate.rb
135
136
  - lib/orchestrate/api.rb
136
137
  - lib/orchestrate/api/errors.rb
138
+ - lib/orchestrate/api/helpers.rb
139
+ - lib/orchestrate/api/response.rb
137
140
  - lib/orchestrate/client.rb
138
- - lib/orchestrate/configuration.rb
139
- - lib/orchestrate/helpers.rb
140
141
  - lib/orchestrate/version.rb
141
142
  - orchestrate.gemspec
142
143
  - test/orchestrate/api/collections_test.rb
143
144
  - test/orchestrate/api/event_test.rb
145
+ - test/orchestrate/api/exceptions_test.rb
144
146
  - test/orchestrate/api/graph_test.rb
145
147
  - test/orchestrate/api/key_value_test.rb
148
+ - test/orchestrate/api/response_test.rb
146
149
  - test/orchestrate/client_test.rb
147
- - test/orchestrate/configuration_test.rb
148
150
  - test/test_helper.rb
149
151
  homepage: https://github.com/orchestrate-io/orchestrate-ruby
150
152
  licenses:
@@ -173,8 +175,10 @@ summary: Ruby client for Orchestrate.io
173
175
  test_files:
174
176
  - test/orchestrate/api/collections_test.rb
175
177
  - test/orchestrate/api/event_test.rb
178
+ - test/orchestrate/api/exceptions_test.rb
176
179
  - test/orchestrate/api/graph_test.rb
177
180
  - test/orchestrate/api/key_value_test.rb
181
+ - test/orchestrate/api/response_test.rb
178
182
  - test/orchestrate/client_test.rb
179
- - test/orchestrate/configuration_test.rb
180
183
  - test/test_helper.rb
184
+ has_rdoc:
@@ -1,53 +0,0 @@
1
- require "logger"
2
-
3
- module Orchestrate
4
-
5
- #
6
- # Represents the configuration for the Orchestrate library, including
7
- # values for the api key, base url and other settings.
8
- #
9
- # An instance of this class is always available at Orchestrate.config.
10
- # You should not
11
- # instantiate instances of this class, instead, you should configure the
12
- # library with the Orchestrate.configure method.
13
- #
14
- # === Example
15
- #
16
- # Orchestrate.configure do |config|
17
- # config.api_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
18
- # end
19
- #
20
- class Configuration
21
-
22
- #
23
- # The api key for your app, from the Orchestrate Dashboard.
24
- #
25
- attr_accessor :api_key
26
-
27
- #
28
- # The url to the Orchestrate API. Defaults to \https://api.orchestrate.io/v0.
29
- #
30
- attr_accessor :base_url
31
-
32
- #
33
- # The logger instances to send messages to. Defaults to +STDOUT+.
34
- #
35
- attr_accessor :logger
36
-
37
- # for faraday, here temporarily
38
- #
39
- attr_accessor :faraday
40
-
41
- #
42
- # Initialize and return a new instance of Configuration.
43
- #
44
- def initialize(options = {}) # :nodoc:
45
- @api_key = options[:api_key]
46
- @base_url = options[:base_url] || "https://api.orchestrate.io"
47
- @logger = options[:logger] || Logger.new(STDOUT)
48
- @faraday = options[:faraday]
49
- end
50
-
51
- end
52
-
53
- end
@@ -1,22 +0,0 @@
1
- module Orchestrate
2
- module Helpers
3
-
4
- extend self
5
-
6
- # * required: type, params={}
7
- #
8
- # Given a params object such as { start: ..., end: ... } and a type such as 'event',
9
- # will return a hash with those parameters formatted for the Orchestrate API, f.e.:
10
- # { 'startEvent' => ..., 'endEvent' => ... }
11
- def range_keys!(type, params)
12
- type = type.capitalize
13
- [:start, :end, :before, :after].each do |key|
14
- if params[key]
15
- params["#{key}#{type}"] = params[key]
16
- params.delete(key)
17
- end
18
- end
19
- end
20
-
21
- end
22
- end
@@ -1,67 +0,0 @@
1
- require "test_helper"
2
-
3
- describe Orchestrate::Configuration do
4
-
5
- before do
6
- @config = Orchestrate::Configuration.new
7
- end
8
-
9
- it "should initialize" do
10
- config = Orchestrate::Configuration.new
11
- config.must_be_kind_of Orchestrate::Configuration
12
- end
13
-
14
- it "should initialize with arguments" do
15
- logger = Logger.new(STDOUT)
16
- config = Orchestrate::Configuration.new \
17
- api_key: "test-key",
18
- base_url: "test-url",
19
- logger: logger
20
- config.must_be_kind_of Orchestrate::Configuration
21
- config.api_key.must_equal "test-key"
22
- config.base_url.must_equal "test-url"
23
- config.logger.must_equal logger
24
- end
25
-
26
- describe "#api_key" do
27
-
28
- it "should not have a default value" do
29
- @config.api_key.must_be_nil
30
- end
31
-
32
- it "should be settable and gettable" do
33
- @config.api_key = "test-key"
34
- @config.api_key.must_equal "test-key"
35
- end
36
-
37
- end
38
-
39
- describe "#base_url" do
40
-
41
- it "should default to 'https://api.orchestrate.io'" do
42
- @config.base_url.must_equal "https://api.orchestrate.io"
43
- end
44
-
45
- it "should be settable and gettable" do
46
- @config.base_url = "test-url"
47
- @config.base_url.must_equal "test-url"
48
- end
49
-
50
- end
51
-
52
- describe "#logger" do
53
-
54
- it "should default to a Logger instance that outputs to STDOUT" do
55
- @config.logger.must_be_kind_of Logger
56
- @config.logger.instance_variable_get("@logdev").dev.must_equal STDOUT
57
- end
58
-
59
- it "should be settable and gettable" do
60
- logger = Logger.new("/tmp/orchestrate-configuration-logger-test-#{rand}.log")
61
- @config.logger = logger
62
- @config.logger.must_equal logger
63
- end
64
-
65
- end
66
-
67
- end