orchestrate 0.5

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,40 @@
1
+ require "test_helper"
2
+
3
+ describe Orchestrate::Client do
4
+
5
+ it "should initialize" do
6
+ client = Orchestrate::Client.new
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
+ end
18
+
19
+ it "handles parallel requests" do
20
+ @client, @stubs = make_client_and_artifacts
21
+ @stubs.get("/v0/foo") do |env|
22
+ [ 200, response_headers, {}.to_json ]
23
+ end
24
+ @stubs.get("/v0/users/mattly") do |env|
25
+ [ 200, response_headers, {}.to_json ]
26
+ end
27
+ responses = nil
28
+ capture_warnings do
29
+ responses = @client.in_parallel do |r|
30
+ r[:list] = @client.list(:foo)
31
+ r[:user] = @client.get(:users, "mattly")
32
+ end
33
+ end
34
+ assert responses[:list]
35
+ assert_equal 200, responses[:list].status
36
+ assert responses[:user]
37
+ assert_equal 200, responses[:user].status
38
+ end
39
+
40
+ end
@@ -0,0 +1,67 @@
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
@@ -0,0 +1,80 @@
1
+ require "orchestrate/api"
2
+ require "minitest/autorun"
3
+ require "json"
4
+ require "base64"
5
+ require "faraday"
6
+ require "securerandom"
7
+ require "time"
8
+
9
+ # Test Helpers ---------------------------------------------------------------
10
+
11
+ def output_message(name, msg = nil)
12
+ msg = "START TEST" if msg.blank?
13
+ Orchestrate.config.logger.debug "\n======= #{msg}: #{name} ======="
14
+ end
15
+
16
+ # TODO this is a bit messy for now at least but there's a bunch of
17
+ # intermediate state we'd have to deal with in a bunch of other places
18
+ def make_client_and_artifacts
19
+ api_key = SecureRandom.hex(24)
20
+ basic_auth = "Basic #{Base64.encode64("#{api_key}:").gsub(/\n/,'')}"
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"))
29
+ end
30
+ client = Orchestrate::Client.new
31
+ [client, stubs, basic_auth]
32
+ end
33
+
34
+ def capture_warnings
35
+ old, $stderr = $stderr, StringIO.new
36
+ begin
37
+ yield
38
+ $stderr.string
39
+ ensure
40
+ $stderr = old
41
+ end
42
+ end
43
+
44
+ def response_headers(specified={})
45
+ {
46
+ 'Content-Type' => 'application/json',
47
+ 'X-Orchestrate-Req-Id' => SecureRandom.uuid,
48
+ 'Date' => Time.now.httpdate,
49
+ 'Connection' => 'keep-alive'
50
+ }.merge(specified)
51
+ end
52
+
53
+ def chunked_encoding_header
54
+ { 'transfer-encoding' => 'chunked' }
55
+ end
56
+
57
+ def response_not_found(items)
58
+ { "message" => "The requested items could not be found.",
59
+ "details" => {
60
+ "items" => [ items ]
61
+ },
62
+ "code" => "items_not_found"
63
+ }.to_json
64
+ end
65
+
66
+ # Assertion Helpers
67
+
68
+ def assert_header(header, expected, env)
69
+ assert_equal expected, env.request_headers[header]
70
+ end
71
+
72
+ def assert_authorization(expected, env)
73
+ assert_header 'Authorization', expected, env
74
+ end
75
+
76
+ def assert_accepts_json(env)
77
+ assert_match %r{application/json}, env.request_headers['Accept']
78
+ end
79
+
80
+
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orchestrate
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.5'
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Lyon
8
+ - Justin Mecham
9
+ - James Carrasquer
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-05-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.9'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '0.9'
29
+ - !ruby/object:Gem::Dependency
30
+ name: faraday_middleware
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '0.9'
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 0.9.1
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '0.9'
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 0.9.1
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.6'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.6'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ - !ruby/object:Gem::Dependency
78
+ name: typhoeus
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ - !ruby/object:Gem::Dependency
92
+ name: em-http-request
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ - !ruby/object:Gem::Dependency
106
+ name: em-synchrony
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ description: Client for the Orchestrate REST API
120
+ email:
121
+ - matthew@lyonheart.us
122
+ - justin@mecham.me
123
+ - jimcar@aracnet.com
124
+ executables: []
125
+ extensions: []
126
+ extra_rdoc_files: []
127
+ files:
128
+ - ".gitignore"
129
+ - ".travis.yml"
130
+ - Gemfile
131
+ - LICENSE
132
+ - README.md
133
+ - Rakefile
134
+ - lib/orchestrate.rb
135
+ - lib/orchestrate/api.rb
136
+ - lib/orchestrate/api/errors.rb
137
+ - lib/orchestrate/api/extensions.rb
138
+ - lib/orchestrate/client.rb
139
+ - lib/orchestrate/configuration.rb
140
+ - lib/orchestrate/helpers.rb
141
+ - lib/orchestrate/version.rb
142
+ - orchestrate.gemspec
143
+ - test/orchestrate/api/collections_test.rb
144
+ - test/orchestrate/api/event_test.rb
145
+ - test/orchestrate/api/graph_test.rb
146
+ - test/orchestrate/api/key_value_test.rb
147
+ - test/orchestrate/client_test.rb
148
+ - test/orchestrate/configuration_test.rb
149
+ - test/test_helper.rb
150
+ homepage: https://github.com/orchestrate-io/orchestrate-ruby
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.0.3
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Ruby client for Orchestrate.io
174
+ test_files:
175
+ - test/orchestrate/api/collections_test.rb
176
+ - test/orchestrate/api/event_test.rb
177
+ - test/orchestrate/api/graph_test.rb
178
+ - test/orchestrate/api/key_value_test.rb
179
+ - test/orchestrate/client_test.rb
180
+ - test/orchestrate/configuration_test.rb
181
+ - test/test_helper.rb