rest_shifter 0.0.11 → 0.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e5c6f62b6e629086fcd6b7445d7c7e9c0d7977b
4
- data.tar.gz: a2d921e1a9820b0846dc92a2cfba0579d5020c02
3
+ metadata.gz: 087d1c4826f3050b7a8fc6845425704d2d2d625d
4
+ data.tar.gz: e29bc423be8e0925d3086c7d226f274795d65ea1
5
5
  SHA512:
6
- metadata.gz: c7fba39d5774aee26ac6efa5a8b3c1acd7ba0756b157bd07281f57d1757fef68b23dd1f8d977eb7d3f6a40a7898d23b2efa81184961a959dd5f130f3e3e8473b
7
- data.tar.gz: 44c7b1a22ebec0a5660db1399061e9903ff9c53485726998f0972f664a2fec4dbc4dde00ac002a7ca45f00e797092b0cf11a09cbedf8dffc0f296a3caebf4208
6
+ metadata.gz: e373a1efda9dcf94839ff68cb5e5d72cfbf869edcc2b0616d9d3ecdb3715a305c0ac0f494060140ad871197167883abe54e4f14176182eb0b02246a6a28f50f7
7
+ data.tar.gz: 0f580e7a6c1b89239422235bb9e90cb617458923468e250f3f95b88ecb89630eadbe213135f638778a09876681897d258d7686b1dfa85f20f96b00ad2f4ce5b6
data/.travis.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.9.3
4
+ - 2.0.0
3
5
  - 2.1.0
6
+ - 2.2.0
4
7
  env:
5
8
  - RACK_ENV=test
data/CHANGES CHANGED
@@ -1,4 +1,12 @@
1
1
 
2
+ ** 0.0.13
3
+ - Feature
4
+ -- Adding support to DELETE and PUT http methods
5
+
6
+ ** 0.0.12
7
+ - Code improvement
8
+ -- Just removing code ;)
9
+
2
10
  ** 0.0.11
3
11
  - Feature
4
12
  -- Now it is possible to start a service with https
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rest_shifter.png)](https://rubygems.org/gems/rest_shifter)
4
4
  [![Build Status](https://secure.travis-ci.org/camiloribeiro/RestShifter.png)](http://travis-ci.org/camiloribeiro/RestShifter)
5
+ [![Code Climate](https://codeclimate.com/github/camiloribeiro/RestShifter/badges/gpa.svg)](https://codeclimate.com/github/camiloribeiro/RestShifter)
6
+ [![Test Coverage](https://codeclimate.com/github/camiloribeiro/RestShifter/badges/coverage.svg)](https://codeclimate.com/github/camiloribeiro/RestShifter)
5
7
  [![endorse](https://api.coderwall.com/camiloribeiro/endorsecount.png)](https://coderwall.com/camiloribeiro)
6
8
 
7
9
 
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
1
  require 'rspec/core/rake_task'
2
- require 'coveralls/rake/task'
3
2
 
4
- Coveralls::RakeTask.new
5
-
6
- task :default => [:spec, 'coveralls:push']
3
+ task :default => [:spec]
7
4
 
8
5
  RSpec::Core::RakeTask .new(:spec) do |task|
9
6
  task.rspec_opts = ["--format documentation"]
@@ -1,23 +1,18 @@
1
1
  require 'sinatra/base'
2
2
  require 'icecream'
3
3
  require 'rack/ssl'
4
+ require 'webrick/https'
4
5
 
5
6
  module RestShifter; end
6
7
 
7
8
  class Shifter < Sinatra::Base
8
9
 
9
10
  def self.run_ssl! crt, key
10
- require 'webrick/https'
11
-
12
- port = 4433
13
- certificate_content = File.open(crt).read
14
- key_content = File.open(key).read
15
-
16
11
  server_options = {
17
- :Port => port,
12
+ :Port => 4433,
18
13
  :SSLEnable => true,
19
- :SSLCertificate => OpenSSL::X509::Certificate.new(certificate_content),
20
- :SSLPrivateKey => OpenSSL::PKey::RSA.new(key_content),
14
+ :SSLCertificate => OpenSSL::X509::Certificate.new(File.open(crt).read),
15
+ :SSLPrivateKey => OpenSSL::PKey::RSA.new(File.open(key).read),
21
16
  :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE
22
17
  }
23
18
 
@@ -26,9 +21,6 @@ class Shifter < Sinatra::Base
26
21
  server.threaded = settings.threaded if server.respond_to? :threaded=
27
22
  set :running, true
28
23
  end
29
- set :ssl, true
30
- set :port, 4433
31
- run!
32
24
  end
33
25
 
34
26
  shapes = IceCream::IceCream.new File.dirname("#{Dir.home}/.rest_shifter/flavors/*")
@@ -41,47 +33,24 @@ class Shifter < Sinatra::Base
41
33
  services << shapes.flavor(shape.to_s.gsub!("@", "").to_sym)
42
34
  end
43
35
 
44
- gets = services.select { |service| service.method_used == "get" }
45
- gets_paths = gets.map { |service| service.path }.uniq
46
-
47
- posts = services.select { |service| service.method_used == "post" }
48
- posts_paths = gets.map { |service| service.path }.uniq
49
-
50
- gets.each do |service|
51
- if service.request_accept.to_s == ''
52
- get service.path do
53
- sleep service.response_sleep
54
- status service.response_status
55
- content_type service.response_content_type
56
- service.response_body
57
- end
58
- else
59
- get service.path, :provides => service.request_accept.to_s == '' ? "" : service.request_accept do
60
- sleep service.response_sleep
61
- status service.response_status
62
- content_type service.response_content_type
63
- service.response_body
64
- end
65
- end
66
- end
67
-
68
- posts.each do |service|
69
- if service.request_accept.to_s == ''
70
- post service.path do
71
- sleep service.response_sleep
72
- status service.response_status
73
- content_type service.response_content_type
74
- service.response_body
75
- end
76
- else
77
- post service.path, :provides => service.request_accept.to_s == '' ? "" : service.request_accept do
78
- sleep service.response_sleep
79
- status service.response_status
80
- content_type service.response_content_type
81
- service.response_body
36
+ def self.build_services operation
37
+ operation.each do |service|
38
+ if service.request_accept.to_s == ''
39
+ send(service.method_used.to_sym, service.path) do
40
+ sleep service.response_sleep
41
+ status service.response_status
42
+ content_type service.response_content_type
43
+ service.response_body
44
+ end
45
+ else
46
+ send(service.method_used.to_sym, service.path, :provides => service.request_accept.to_s == '' ? "" : service.request_accept) do
47
+ sleep service.response_sleep
48
+ status service.response_status
49
+ content_type service.response_content_type
50
+ service.response_body
51
+ end
82
52
  end
83
53
  end
84
54
  end
85
-
86
-
55
+ build_services services
87
56
  end
@@ -1,3 +1,3 @@
1
1
  module RestShifter
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.13"
3
3
  end
data/rest_shifter.gemspec CHANGED
@@ -21,13 +21,12 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_development_dependency 'simplecov'
24
+ s.add_development_dependency 'codeclimate-test-reporter'
25
25
  s.add_development_dependency 'pry'
26
26
  s.add_development_dependency 'cucumber'
27
27
  s.add_development_dependency 'rake'
28
28
  s.add_development_dependency 'rest-client'
29
29
  s.add_development_dependency 'rspec'
30
- s.add_development_dependency 'coveralls'
31
30
  s.add_development_dependency 'nyan-cat-formatter'
32
31
  s.add_development_dependency 'rack-test'
33
32
 
@@ -1,8 +1,8 @@
1
1
  method_used = "post"
2
2
  path = "/notfound"
3
- request_accept = ""
4
- request_content_type = ""
3
+ request_accept = "text/plain"
4
+ request_content_type = ""
5
5
  response_sleep = 0
6
- response_status = "404"
7
- response_body = "Not Found"
8
- response_content_type = "application/foo.company.product.type-version+json"
6
+ response_status = "201"
7
+ response_body = "This is just a text"
8
+ response_content_type = "text/plain"
@@ -0,0 +1,8 @@
1
+ method_used = "post"
2
+ path = "/notfound"
3
+ request_accept = "application/json"
4
+ request_content_type = ""
5
+ response_sleep = 0
6
+ response_status = "200"
7
+ response_body = "Found"
8
+ response_content_type = "application/json"
@@ -0,0 +1,8 @@
1
+ method_used = "post"
2
+ path = "/sleep"
3
+ request_accept = ""
4
+ request_content_type = ""
5
+ response_sleep = 1
6
+ response_status = "200"
7
+ response_body = "This should sleep for one second"
8
+ response_content_type = "application/json"
@@ -0,0 +1,8 @@
1
+ method_used = "delete"
2
+ path = "/ok"
3
+ request_accept = ""
4
+ request_content_type = ""
5
+ response_sleep = 0
6
+ response_status = "200"
7
+ response_body = "delete success"
8
+ response_content_type = "application/json"
@@ -0,0 +1,8 @@
1
+ method_used = "put"
2
+ path = "/ok"
3
+ request_accept = ""
4
+ request_content_type = ""
5
+ response_sleep = 0
6
+ response_status = "200"
7
+ response_body = "put success"
8
+ response_content_type = "application/json"
data/spec/service_spec.rb CHANGED
@@ -9,14 +9,14 @@ describe RestShifter do
9
9
 
10
10
  describe Shifter do
11
11
  describe "Get Operations" do
12
- it "Endpoint for get" do
12
+ it "GET: Endpoint for get" do
13
13
  get '/ok'
14
14
  expect(last_response.status).to eq(200)
15
15
  expect(last_response.body).to eq("success")
16
16
  expect(last_response.headers['Content-Type']).to eq("application/json")
17
17
  end
18
18
 
19
- it "Known bug: Return 400 when has no endpoint with specified accept" do
19
+ it "GET: Known bug: Return 400 when has no endpoint with specified accept" do
20
20
  header 'Accept', 'application/xml'
21
21
  get '/notfound'
22
22
  expect(last_response.status).to eq(404)
@@ -24,7 +24,7 @@ describe RestShifter do
24
24
  expect(last_response.headers['Content-Type']).to eq("text/html;charset=utf-8")
25
25
  end
26
26
 
27
- it "Should choose right endpoint based on accept header - text" do
27
+ it "GET: Should choose right endpoint based on accept header - text" do
28
28
  header 'Accept', 'text/plain'
29
29
  get '/notfound'
30
30
  expect(last_response.status).to eq(201)
@@ -32,7 +32,7 @@ describe RestShifter do
32
32
  expect(last_response.headers['Content-Type']).to eq("text/plain;charset=utf-8")
33
33
  end
34
34
 
35
- it "Should choose right endpoint based on accept header - json" do
35
+ it "GET: Should choose right endpoint based on accept header - json" do
36
36
  header 'Accept', 'application/json'
37
37
  get '/notfound'
38
38
  expect(last_response.status).to eq(200)
@@ -42,23 +42,56 @@ describe RestShifter do
42
42
 
43
43
  end
44
44
  describe "Post operations" do
45
- it "Endpoint for post" do
45
+ it "POST: Endpoint for post" do
46
46
  post '/ok'
47
47
  expect(last_response.status).to eq(200)
48
48
  expect(last_response.body).to eq("success")
49
49
  expect(last_response.headers['Content-Type']).to eq("application/json")
50
50
  end
51
51
 
52
- it "Common endpoint with get should behave like post when using post" do
52
+ it "POST: Known bug: Return 400 when has no endpoint with specified accept" do
53
+ header 'Accept', 'application/xml'
53
54
  post '/notfound'
54
55
  expect(last_response.status).to eq(404)
55
- expect(last_response.body).to eq("Not Found")
56
- expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version+json")
56
+ expect(last_response.body).to eq("<h1>Not Found</h1>")
57
+ expect(last_response.headers['Content-Type']).to eq("text/html;charset=utf-8")
58
+ end
59
+
60
+ it "POST: Should choose right endpoint based on accept header - text" do
61
+ header 'Accept', 'text/plain'
62
+ post '/notfound'
63
+ expect(last_response.status).to eq(201)
64
+ expect(last_response.body).to eq("This is just a text")
65
+ expect(last_response.headers['Content-Type']).to eq("text/plain;charset=utf-8")
57
66
  end
58
67
 
68
+ it "POST: Should choose right endpoint based on accept header - json" do
69
+ header 'Accept', 'application/json'
70
+ post '/notfound'
71
+ expect(last_response.status).to eq(200)
72
+ expect(last_response.body).to eq("Found")
73
+ expect(last_response.headers['Content-Type']).to eq("application/json")
74
+ end
75
+
76
+ end
77
+ describe "Put Operations" do
78
+ it "PUT: Endpoint for put" do
79
+ put '/ok'
80
+ expect(last_response.status).to eq(200)
81
+ expect(last_response.body).to eq("put success")
82
+ expect(last_response.headers['Content-Type']).to eq("application/json")
83
+ end
84
+ end
85
+ describe "Delete Operations" do
86
+ it "DELETE: Endpoint for delete" do
87
+ delete '/ok'
88
+ expect(last_response.status).to eq(200)
89
+ expect(last_response.body).to eq("delete success")
90
+ expect(last_response.headers['Content-Type']).to eq("application/json")
91
+ end
59
92
  end
60
93
  describe "Special behaviours" do
61
- it "Service should sleep for a second" do
94
+ it "GET: Service should sleep for a second" do
62
95
  time = Time.now
63
96
  get '/sleep'
64
97
  expect(Time.now - time).to be > 1
@@ -66,6 +99,14 @@ describe RestShifter do
66
99
  expect(last_response.body).to eq("This should sleep for one second")
67
100
  expect(last_response.headers['Content-Type']).to eq("application/json")
68
101
  end
102
+ it "POST: Service should sleep for a second" do
103
+ time = Time.now
104
+ post '/sleep'
105
+ expect(Time.now - time).to be > 1
106
+ expect(last_response.status).to eq(200)
107
+ expect(last_response.body).to eq("This should sleep for one second")
108
+ expect(last_response.headers['Content-Type']).to eq("application/json")
109
+ end
69
110
  end
70
111
  end
71
112
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  require 'rspec'
2
- require 'coveralls'
3
2
  require 'rest_client'
4
3
  require 'rack/test'
4
+ require "codeclimate-test-reporter"
5
+ CodeClimate::TestReporter.start
5
6
 
6
7
  require File.join(File.dirname(__FILE__), '../lib/rest_shifter/shifter.rb')
7
8
  ENV['RACK_ENV'] = 'test'
8
9
 
9
- Coveralls.wear_merged!
10
-
11
10
  module RSpecMixin
12
11
  include Rack::Test::Methods
13
12
  def app() Sinatra::Application end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_shifter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camilo Ribeiro
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2015-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: simplecov
14
+ name: codeclimate-test-reporter
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: coveralls
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - '>='
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: nyan-cat-formatter
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -210,9 +196,13 @@ files:
210
196
  - spec/flavors/notfound_get.flavor
211
197
  - spec/flavors/notfound_get_accept.flavor
212
198
  - spec/flavors/notfound_post.flavor
199
+ - spec/flavors/notfound_post_accept.flavor
213
200
  - spec/flavors/sleep_get.flavor
201
+ - spec/flavors/sleep_post.flavor
202
+ - spec/flavors/success_delete.flavor
214
203
  - spec/flavors/success_get.flavor
215
204
  - spec/flavors/success_post.flavor
205
+ - spec/flavors/success_put.flavor
216
206
  - spec/service_spec.rb
217
207
  - spec/spec_helper.rb
218
208
  homepage: http://github.com/camiloribeiro/RestShifter
@@ -243,8 +233,12 @@ test_files:
243
233
  - spec/flavors/notfound_get.flavor
244
234
  - spec/flavors/notfound_get_accept.flavor
245
235
  - spec/flavors/notfound_post.flavor
236
+ - spec/flavors/notfound_post_accept.flavor
246
237
  - spec/flavors/sleep_get.flavor
238
+ - spec/flavors/sleep_post.flavor
239
+ - spec/flavors/success_delete.flavor
247
240
  - spec/flavors/success_get.flavor
248
241
  - spec/flavors/success_post.flavor
242
+ - spec/flavors/success_put.flavor
249
243
  - spec/service_spec.rb
250
244
  - spec/spec_helper.rb