loaderio 0.0.1

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,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rspec
6
+ coverage/**
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in loaderio.gemspec
4
+ gemspec
@@ -0,0 +1,66 @@
1
+ # ruby client for loader.io api
2
+
3
+ ## Installing
4
+
5
+ Add to your 'Gemfile':
6
+
7
+ ```ruby
8
+ gem 'loaderio'
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```ruby
14
+ Loaderio::Configuration.api_key = "your_api_key"
15
+ ```
16
+
17
+ ## Application
18
+
19
+ ### Applications
20
+ ```ruby
21
+ Loaderio::Application.all
22
+ => [#<Loaderio::Application:0x007f8615393af8 >, #<Loaderio::Application:0x007f86153939e0>]
23
+ ```
24
+
25
+ ### Find application
26
+ ```ruby
27
+ Loaderio::Application.find "app_id"
28
+ => #<Loaderio::Application:0x007fd232fe5338>
29
+ ```
30
+
31
+ ### Create application
32
+ ```ruby
33
+ Loaderio::Application.create(app: "example.com")
34
+ => #<Loaderio::Application:0x007fd232fe5338
35
+ ```
36
+ ### Verify application
37
+ ```ruby
38
+ Loaderio::Application.verify("app_id")
39
+ => #<Loaderio::Application:0x007fd23301b7f8>
40
+ ```
41
+
42
+ ## Test
43
+
44
+ ### Tests
45
+ ```ruby
46
+ Loaderio::Test.all
47
+ => [#<Loaderio::Test:0x007fd232066290>, #<Loaderio::Test:0x007fd2320661c8>]
48
+ ```
49
+
50
+ ### Find test
51
+ ```ruby
52
+ Loaderio::Test.find("test_id")
53
+ => #<Loaderio::Test:0x007fd2320eefc8>
54
+ ```
55
+
56
+ ### Create test
57
+ ```ruby
58
+ Loaderio::Test.create(url: "http://example.com", load: "0-10-10")
59
+ => #<Loaderio::Test:0x007fd232131ee0>
60
+ ```
61
+
62
+ ### Test results
63
+ ```ruby
64
+ Loaderio::Test.results("app_id")
65
+ => #<Loaderio::Test:0x007fd2320eefc8>
66
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ require 'ostruct'
2
+ require 'rest_client'
3
+ require 'multi_json'
4
+
5
+ require "loaderio/base"
6
+ require "loaderio/application"
7
+ require "loaderio/test"
8
+ require "loaderio/configuration"
9
+ require "loaderio/version"
@@ -0,0 +1,22 @@
1
+ module Loaderio
2
+ class Application < Base
3
+ attr_reader :app_id, :app, :status
4
+
5
+ def initialize(attributes)
6
+ @app_id, @app, @status = attributes[:app_id], attributes[:app], attributes[:status]
7
+ super
8
+ end
9
+
10
+ def self.resource_name
11
+ "apps"
12
+ end
13
+
14
+ def self.verify(app_id)
15
+ new(parse(Loaderio::Configuration.resource["#{resource_name}/#{app_id}/verify"].post({})))
16
+ end
17
+
18
+ def verification_id
19
+ "loaderio-#{app_id}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ module Loaderio
2
+ class Base
3
+ attr_reader :message, :errors
4
+
5
+ def initialize(attributes)
6
+ @message, @errors = attributes[:message] || "success", attributes[:errors]
7
+ end
8
+
9
+ def valid?
10
+ @message == "success"
11
+ end
12
+
13
+ alias_method :success?, :valid?
14
+
15
+ def self.resource_name
16
+ raise "resource name was not specified"
17
+ end
18
+
19
+ def self.all
20
+ parse(Loaderio::Configuration.resource["#{resource_name}"].get).map do |item|
21
+ new(item)
22
+ end
23
+ end
24
+
25
+ def self.find(id)
26
+ new(parse(Loaderio::Configuration.resource["#{resource_name}/#{id}"].get))
27
+ end
28
+
29
+ def self.create(attrs)
30
+ new(parse(Loaderio::Configuration.resource["#{resource_name}"].post(attrs)))
31
+ end
32
+
33
+ private
34
+
35
+ def self.parse(responce)
36
+ MultiJson.load(responce, :symbolize_keys => true)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ module Loaderio
2
+ module Configuration
3
+ extend self
4
+
5
+ attr_accessor :api_key, :api_version, :protocol
6
+
7
+ #default values
8
+ self.api_version = "v1"
9
+ self.protocol = "https"
10
+
11
+ def server
12
+ "api.loader.io"
13
+ end
14
+
15
+ def base_url
16
+ "#{protocol}://#{server}/#{api_version}"
17
+ end
18
+
19
+ def resource
20
+ @resource ||= RestClient::Resource.new(base_url, headers: {"loaderio-Auth" => api_key, content_type: :json, accept: :json })
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Loaderio
2
+ class Test < Base
3
+ attr_reader :url, :name, :duration, :timeout, :from, :to, :status, :test_id, :request_type, :results_data
4
+
5
+ def initialize(attributes)
6
+ @url = attributes[:url]
7
+ @name = attributes[:name]
8
+ @duration = attributes[:duration]
9
+ @timeout = attributes[:timeout]
10
+ @from = attributes[:from]
11
+ @to = attributes[:to]
12
+ @status = attributes[:status]
13
+ @test_id = attributes[:test_id]
14
+ @request_type = attributes[:request_type]
15
+ @results_data = OpenStruct.new(attributes[:results_data])
16
+ super
17
+ end
18
+
19
+ def self.resource_name
20
+ "tests"
21
+ end
22
+
23
+ def self.results(id)
24
+ new(parse(Loaderio::Configuration.resource["#{resource_name}/#{id}/results"].get))
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Loaderio
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "loaderio/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "loaderio"
6
+ s.version = Loaderio::VERSION
7
+ s.authors = ["paladiy"]
8
+ s.email = ["olexanderpaladiy@gmail.com"]
9
+ s.homepage = ""
10
+ s.summary = %q{loader.io ruby api client}
11
+ s.description = %q{loader.io ruby api client}
12
+
13
+ s.rubyforge_project = "loaderio"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "rspec", "~> 2.12.0"
21
+ s.add_development_dependency "simplecov", "~> 0.7.1"
22
+
23
+ s.add_runtime_dependency "rest-client", "~> 1.6.7"
24
+ s.add_runtime_dependency "oj", "~> 2.0.0"
25
+ s.add_runtime_dependency "multi_json", "~> 1.5.0"
26
+ end
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start do
4
+ add_filter '/spec/'
5
+
6
+ add_group 'Libraries', '/lib/'
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ require "loaderio"
11
+
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ config.order = 'random'
17
+ end
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+
3
+ describe Loaderio::Application do
4
+ let(:attributes){ { app: "localhost.local", app_id: "fake-app-id", status: "verified" } }
5
+ let(:application){ described_class.new(attributes) }
6
+
7
+ let(:resource){ Loaderio::Configuration.resource }
8
+
9
+ subject{ application }
10
+
11
+ shared_examples_for "application attributes" do
12
+ its(:app){ should == "localhost.local" }
13
+ its(:app_id){ should == "fake-app-id" }
14
+ its(:status){ should == "verified" }
15
+ end
16
+
17
+ it_should_behave_like "application attributes"
18
+
19
+ context ".all" do
20
+ let(:collection){ described_class.all }
21
+
22
+ subject{ collection }
23
+
24
+ before do
25
+ resource.should_receive(:[]).with("apps").and_return(resource)
26
+ resource.should_receive(:get).and_return(MultiJson.dump([attributes, attributes]))
27
+ end
28
+
29
+ it{ should have(2).items }
30
+
31
+ context "with element" do
32
+ subject{ collection[0] }
33
+
34
+ it_should_behave_like "application attributes"
35
+ end
36
+ end
37
+
38
+ context ".find" do
39
+ let(:instance){ described_class.find("fake-app-id") }
40
+
41
+ subject{ instance }
42
+
43
+ before do
44
+ resource.should_receive(:[]).with("apps/fake-app-id").and_return(resource)
45
+ resource.should_receive(:get).and_return(MultiJson.dump(attributes))
46
+ end
47
+
48
+ it_should_behave_like "application attributes"
49
+ end
50
+
51
+ context ".create" do
52
+ let(:responce){ { message: "success", app_id: "fake-app-id", verification_id: "loaderio-fake-app-id" } }
53
+
54
+ subject{ described_class.create app: "localhost.local"}
55
+
56
+ before do
57
+ resource.should_receive(:[]).with("apps").and_return(resource)
58
+ resource.should_receive(:post).with(app: "localhost.local").and_return(MultiJson.dump(responce))
59
+ end
60
+
61
+ its(:app_id){ should == "fake-app-id" }
62
+ its(:app){ should be_nil }
63
+ its(:status){ should be_nil }
64
+ end
65
+
66
+ context ".verify" do
67
+ let(:responce){ { app_id: "fake-app-id", message: "success" }}
68
+
69
+ subject{ described_class.verify("fake-app-id") }
70
+
71
+ before do
72
+ resource.should_receive(:[]).with("apps/fake-app-id/verify").and_return(resource)
73
+ resource.should_receive(:post).with({}).and_return(MultiJson.dump(responce))
74
+ end
75
+
76
+ its(:app_id){ should == "fake-app-id" }
77
+ its(:app){ should be_nil }
78
+ its(:status){ should be_nil }
79
+ end
80
+
81
+ context "#verification_id" do
82
+ subject{ application.verification_id }
83
+
84
+ it{ should == "loaderio-fake-app-id" }
85
+ end
86
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe Loaderio::Base do
4
+ let(:attributes){ { message: "error", errors: ["Invalid record"] } }
5
+ let(:instance){ described_class.new attributes }
6
+
7
+ subject{ instance }
8
+
9
+ its(:message){ should == "error" }
10
+ its(:errors){ should == ["Invalid record"] }
11
+
12
+ context ".resource_name" do
13
+ subject{ described_class.resource_name }
14
+
15
+ it{ lambda{ subject }.should raise_error }
16
+ end
17
+
18
+ context "#valid?" do
19
+ subject{ instance }
20
+
21
+ context "when error" do
22
+ let(:attributes){ { message: "error" } }
23
+
24
+ it{ should_not be_valid }
25
+ it{ should_not be_success }
26
+ end
27
+
28
+ context "when success" do
29
+ let(:attributes){ { message: "success" } }
30
+
31
+ it{ should be_valid }
32
+ it{ should be_success }
33
+ end
34
+
35
+ context "by default" do
36
+ let(:attributes){ {} }
37
+
38
+ it{ should be_valid }
39
+ it{ should be_success }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe Loaderio::Configuration do
4
+ context "#protocol" do
5
+ subject{ described_class.protocol }
6
+
7
+ it{ should == "https" }
8
+ end
9
+
10
+ context "#api_version" do
11
+ subject{ described_class.api_version }
12
+
13
+ it{ should == "v1" }
14
+ end
15
+
16
+ context "#api_key" do
17
+ subject{ described_class.api_key }
18
+
19
+ before{ described_class.api_key = "api_key" }
20
+
21
+ it{ should == "api_key" }
22
+ end
23
+
24
+ context "#server" do
25
+ subject{ described_class.server }
26
+
27
+ it{ should == "api.loader.io" }
28
+ end
29
+
30
+ context "#base_url" do
31
+ subject{ described_class.base_url }
32
+
33
+ it{ should == "https://api.loader.io/v1" }
34
+ end
35
+
36
+ context "#resource" do
37
+ subject{ described_class.resource }
38
+
39
+ it{ should be_kind_of(RestClient::Resource) }
40
+ end
41
+ end
@@ -0,0 +1,138 @@
1
+ require "spec_helper"
2
+
3
+ describe Loaderio::Test do
4
+ let(:attributes){
5
+ {
6
+ url: "http://app.loader.io/tests#12",
7
+ name: "name",
8
+ duration: 30,
9
+ timeout: 0,
10
+ from: 0,
11
+ to: 15000,
12
+ status: "complete",
13
+ test_id: "fake-test-id",
14
+ request_type: "GET"
15
+ }
16
+ }
17
+ let(:test){ described_class.new attributes }
18
+
19
+ let(:resource){ Loaderio::Configuration.resource }
20
+
21
+ subject{ test }
22
+
23
+ shared_examples_for "test attributes" do
24
+ its(:url){ should == "http://app.loader.io/tests#12" }
25
+ its(:name){ should == "name" }
26
+ its(:duration){ should == 30 }
27
+ its(:timeout){ should == 0 }
28
+ its(:from){ should == 0 }
29
+ its(:to){ should == 15000 }
30
+ its(:status){ should == "complete" }
31
+ its(:test_id){ should == "fake-test-id" }
32
+ its(:request_type){ should == "GET" }
33
+ end
34
+
35
+ shared_examples_for "test results" do
36
+ its(:started_at){ should == "2012-09-13T10:32:36Z" }
37
+ its(:public_results_url){ should == "http://loader.io/results/1f25f5d42d6839bc30815dc92d301e86" }
38
+ its(:success){ should == 25588 }
39
+ its(:error){ should == 0 }
40
+ its(:timeout_error){ should == 6220 }
41
+ its(:data_sent){ should == 7617840 }
42
+ its(:data_received){ should == 4212000 }
43
+ end
44
+
45
+ it_should_behave_like "test attributes"
46
+
47
+ context ".all" do
48
+ let(:collection){ described_class.all }
49
+
50
+ subject{ collection }
51
+
52
+ before do
53
+ resource.should_receive(:[]).with("tests").and_return(resource)
54
+ resource.should_receive(:get).and_return(MultiJson.dump([attributes, attributes]))
55
+ end
56
+
57
+ it{ should have(2).items }
58
+
59
+ context "with element" do
60
+ subject{ collection[0] }
61
+
62
+ it_should_behave_like "test attributes"
63
+ end
64
+ end
65
+
66
+ context ".find" do
67
+ let(:instance){ described_class.find("fake-test-id") }
68
+
69
+ subject{ instance }
70
+
71
+ before do
72
+ resource.should_receive(:[]).with("tests/fake-test-id").and_return(resource)
73
+ resource.should_receive(:get).and_return(MultiJson.dump(attributes))
74
+ end
75
+
76
+ it_should_behave_like "test attributes"
77
+ end
78
+
79
+ context ".create" do
80
+ let(:results_data){
81
+ {
82
+ started_at: "2012-09-13T10:32:36Z",
83
+ public_results_url: "http://loader.io/results/1f25f5d42d6839bc30815dc92d301e86",
84
+ success: 25588,
85
+ error: 0,
86
+ timeout_error: 6220,
87
+ data_sent: 7617840,
88
+ data_received: 4212000
89
+ }
90
+ }
91
+ let(:responce){ described_class.create(url: "http://app.loader.io/tests#12", load: "0-10-10") }
92
+
93
+ subject{ responce }
94
+
95
+ before do
96
+ resource.should_receive(:[]).with("tests").and_return(resource)
97
+ resource.should_receive(:post).with(url: "http://app.loader.io/tests#12", load: "0-10-10").and_return(MultiJson.dump(attributes.merge(results_data: results_data)))
98
+ end
99
+
100
+ it_should_behave_like "test attributes"
101
+
102
+ context "with results data" do
103
+ subject{ responce.results_data }
104
+
105
+ it_should_behave_like "test results"
106
+ end
107
+ end
108
+
109
+ context ".results" do
110
+ let(:results_data){
111
+ {
112
+ started_at: "2012-09-13T10:32:36Z",
113
+ public_results_url: "http://loader.io/results/1f25f5d42d6839bc30815dc92d301e86",
114
+ success: 25588,
115
+ error: 0,
116
+ timeout_error: 6220,
117
+ data_sent: 7617840,
118
+ data_received: 4212000
119
+ }
120
+ }
121
+ let(:responce){ described_class.results("fake-test-id") }
122
+
123
+ subject{ responce }
124
+
125
+ before do
126
+ resource.should_receive(:[]).with("tests/fake-test-id/results").and_return(resource)
127
+ resource.should_receive(:get).and_return(MultiJson.dump(attributes.merge(results_data: results_data)))
128
+ end
129
+
130
+ it_should_behave_like "test attributes"
131
+
132
+ context "with results data" do
133
+ subject{ responce.results_data }
134
+
135
+ it_should_behave_like "test results"
136
+ end
137
+ end
138
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loaderio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - paladiy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.12.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.12.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: simplecov
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.7.1
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.7.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: rest-client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.6.7
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.7
62
+ - !ruby/object:Gem::Dependency
63
+ name: oj
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.0.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: multi_json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.5.0
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.5.0
94
+ description: loader.io ruby api client
95
+ email:
96
+ - olexanderpaladiy@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - README.md
104
+ - Rakefile
105
+ - lib/loaderio.rb
106
+ - lib/loaderio/application.rb
107
+ - lib/loaderio/base.rb
108
+ - lib/loaderio/configuration.rb
109
+ - lib/loaderio/test.rb
110
+ - lib/loaderio/version.rb
111
+ - loaderio.gemspec
112
+ - spec/spec_helper.rb
113
+ - spec/unit/loaderio/application_spec.rb
114
+ - spec/unit/loaderio/base_spec.rb
115
+ - spec/unit/loaderio/configuration_spec.rb
116
+ - spec/unit/loaderio/test_spec.rb
117
+ homepage: ''
118
+ licenses: []
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project: loaderio
137
+ rubygems_version: 1.8.24
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: loader.io ruby api client
141
+ test_files:
142
+ - spec/spec_helper.rb
143
+ - spec/unit/loaderio/application_spec.rb
144
+ - spec/unit/loaderio/base_spec.rb
145
+ - spec/unit/loaderio/configuration_spec.rb
146
+ - spec/unit/loaderio/test_spec.rb