rest_shifter 0.0.3 → 0.0.4

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: 13a959670c52e25b96fccb8353044bde666e0daa
4
- data.tar.gz: 161ebf3ca1d3e620651262ced5b6c1ce2615dc8b
3
+ metadata.gz: 09b639e5f24da14070930930d7019f52d4ce8b62
4
+ data.tar.gz: 69d83b9265caa43e0dff2406f4af2bc6b62c62ca
5
5
  SHA512:
6
- metadata.gz: a3d7c8e8abbd522ba5fdc71fdc858776bf0c07e75642d0e7f4279122e72c658de85780a73fc9ec797d6835089f29df91e8eb827e5fac91dae81b5bbc62f74e3f
7
- data.tar.gz: 03fb753b4f339f4baa1407d79e50ba76a20ede9794d00bc620e1c0f07e9b0998a629eef87e4359a1b5184b2306c0639f8e03576fee448306b634723076b77338
6
+ metadata.gz: e61926cbbd764d0d35e013e611919eef7455a38c3dc6198bed2784ee07c1c90386a9b4760e7ca7b312d14fb0672cf38b35fe4ecdb152c6778a462b6a87dbca85
7
+ data.tar.gz: caa8295233e1c49e7326a56bf8e41624c0ec04f857a272b6e71564aa13f991bc95559aa1a648b94e39bab9e59798a87b0598af9db00940a39d2ec18a02c9f208
data/CHANGES CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ ** 0.0.4
3
+ - Command -s / start added
4
+ -- Now the gem is able to start its rest service by command line
5
+ - Command -c / create added
6
+ -- Now the gem is able to create a new file to configure a service
7
+
2
8
  ** 0.0.3
3
9
  - Algorithm improvements and big renaming:
4
10
  -- Adding a customizable algorithm that will allow to take decisions based on headers for routing
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest_shifter (0.0.3)
4
+ rest_shifter (0.0.4)
5
5
  icecream
6
6
  sinatra
7
7
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # RestShifter
1
+ # RestShifter (rest_shifter)
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/RestShifter.png)](https://rubygems.org/gems/RestShifter)
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
5
  [![endorse](https://api.coderwall.com/camiloribeiro/endorsecount.png)](https://coderwall.com/camiloribeiro)
6
6
 
@@ -59,7 +59,29 @@ If you have any problems, please let me know.
59
59
  Using
60
60
  -----
61
61
 
62
- Soon.
62
+ The focus here is in simplicity.
63
+
64
+ Install rest_shifter
65
+ $ gem install rest_shifter
66
+
67
+ Create the service (you can choose any name that have only letters and underline. It is required to start with a letter )
68
+ $ rest_shifter -c hello_world
69
+
70
+ Start the service
71
+ $ rest_shifter -s
72
+
73
+ Go to a browser and open the url:
74
+ $ http://localhost:4567/hello_world
75
+
76
+ You should see the following JSON:
77
+ $ { \hello_world\ : \Your service is working fine. :D\ }
78
+
79
+ To edit the service you just created, go to ~/.rest_shifter/flavors/hello_world.flavor
80
+ The name of the file is the name that you used in the command -c (create).
81
+
82
+ Whatever you change in the file will change in the service as soon as you restart it.
83
+
84
+ Enjoy
63
85
 
64
86
  LICENSE
65
87
  =======
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+
3
+ class RestShifter::Commands::Create
4
+ class << self
5
+ def run(args=ARGV)
6
+ name = args.shift + ".flavor"
7
+ dirname = File.dirname("#{Dir.home}/.rest_shifter/flavors/foo")
8
+ FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
9
+ File.open(dirname + "/" + name, 'w') {|f| f.write(
10
+ 'method_used = "get"
11
+ path = "/hello_world"
12
+ response_status = "200"
13
+ response_body = "{ \"hello_world\" : \"Your service is working fine. :D\" }"
14
+ response_content_type = "application/json"') }
15
+ end
16
+ end
17
+ end
@@ -6,6 +6,12 @@ class RestShifter::Commands::Main
6
6
  cmd = args.shift
7
7
 
8
8
  case cmd
9
+ when "-s", "--start", "start"
10
+ RestShifter::Commands::Start.run
11
+ exit 0
12
+ when "-c", "--create", "create"
13
+ RestShifter::Commands::Create.run
14
+ exit 0
9
15
  when "-h", "--help", NilClass
10
16
  RestShifter::Commands::Help.run
11
17
  exit 0
@@ -0,0 +1,14 @@
1
+ class RestShifter::Commands::Start
2
+ def self.run
3
+ begin
4
+ require 'rest_shifter/shifter.rb'
5
+ rescue LoadError => e
6
+ require 'rubygems'
7
+ path = File.expand_path '../../lib', __FILE__
8
+ $:.unshift(path) if File.directory?(path) && !$:.include?(path)
9
+ require 'rest_shifter/shifter.rb'
10
+ end
11
+
12
+ Shifter.run!
13
+ end
14
+ end
@@ -6,33 +6,37 @@ require 'pry'
6
6
  module RestShifter; end
7
7
 
8
8
  class Shifter < Sinatra::Base
9
- end
10
9
 
11
- shapes = IceCream::IceCream.new File.join(File.dirname(__FILE__), "../../spec/flavors")
10
+ # test
11
+ # shapes = IceCream::IceCream.new File.join(File.dirname(__FILE__), "../../spec/flavors")
12
+ # prod
13
+ shapes = IceCream::IceCream.new File.dirname("#{Dir.home}/.rest_shifter/flavors/*")
12
14
 
13
- services = []
14
- shapes.all.each do |shape|
15
- services << shapes.flavor(shape.to_s.gsub!("@", "").to_sym)
16
- end
15
+ services = []
16
+ shapes.all.each do |shape|
17
+ services << shapes.flavor(shape.to_s.gsub!("@", "").to_sym)
18
+ end
17
19
 
18
- gets = services.select { |service| service.method_used == "get" }
19
- gets_paths = gets.map { |service| service.path }.uniq
20
+ gets = services.select { |service| service.method_used == "get" }
21
+ gets_paths = gets.map { |service| service.path }.uniq
20
22
 
21
- posts = services.select { |service| service.method_used == "post" }
22
- posts_paths = gets.map { |service| service.path }.uniq
23
+ posts = services.select { |service| service.method_used == "post" }
24
+ posts_paths = gets.map { |service| service.path }.uniq
23
25
 
24
- gets.each do |service|
25
- get service.path do
26
- status service.response_status
27
- content_type service.response_content_type
28
- service.response_body
26
+ gets.each do |service|
27
+ get service.path do
28
+ status service.response_status
29
+ content_type service.response_content_type
30
+ service.response_body
31
+ end
29
32
  end
30
- end
31
33
 
32
- posts.each do |service|
33
- post service.path do
34
- status service.response_status
35
- content_type service.response_content_type
36
- service.response_body
34
+ posts.each do |service|
35
+ post service.path do
36
+ status service.response_status
37
+ content_type service.response_content_type
38
+ service.response_body
39
+ end
37
40
  end
41
+
38
42
  end
@@ -1,3 +1,3 @@
1
1
  module RestShifter
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/rest_shifter.rb CHANGED
@@ -16,6 +16,8 @@ require 'rest_shifter/commands'
16
16
  require File.join(File.dirname(__FILE__), './rest_shifter/commands/main')
17
17
  require File.join(File.dirname(__FILE__), './rest_shifter/commands/help')
18
18
  require File.join(File.dirname(__FILE__), './rest_shifter/commands/version')
19
+ require File.join(File.dirname(__FILE__), './rest_shifter/commands/start')
20
+ require File.join(File.dirname(__FILE__), './rest_shifter/commands/create')
19
21
 
20
22
  module RestShifter
21
23
  end
data/spec/service_spec.rb CHANGED
@@ -3,50 +3,42 @@ require File.join(File.dirname(__FILE__), '../lib/rest_shifter/shifter.rb')
3
3
 
4
4
  describe RestShifter do
5
5
 
6
- def app
7
- Sinatra::Application
6
+ def app
7
+ Shifter.set :path_to_flavors, File.join(File.dirname(__FILE__), "../../spec/flavors")
8
8
  end
9
9
 
10
- describe "Get Operations" do
11
- # Get
12
- it "Service should return 200 for get" do
13
- get '/ok'
14
- expect(last_response.status).to eq(200)
15
- expect(last_response.body).to eq("success")
16
- expect(last_response.headers['Content-Type']).to eq("application/json")
17
- end
18
-
19
- it "Service should return 404 without accept defining routing for get" do
20
- get '/notfound'
21
- expect(last_response.status).to eq(404)
22
- expect(last_response.body).to eq("Not Found")
23
- expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version+json")
24
- end
10
+ describe Shifter do
11
+ describe "Get Operations" do
12
+ it "Service should return 200 for get" do
13
+ get '/ok'
14
+ expect(last_response.status).to eq(200)
15
+ expect(last_response.body).to eq("success")
16
+ expect(last_response.headers['Content-Type']).to eq("application/json")
17
+ end
18
+
19
+ it "Service should return 404 without accept defining routing for get" do
20
+ get '/notfound'
21
+ expect(last_response.status).to eq(404)
22
+ expect(last_response.body).to eq("Not Found")
23
+ expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version+json")
24
+ end
25
25
 
26
- # it "Service should return 404 with accept defining routing" do
27
- # header 'Accept', "application/foo.company.product.type-version2+json"
28
- # get '/notfound'
29
- # expect(last_response.status).to eq(404)
30
- # expect(last_response.body).to eq("Not Found with accept")
31
- # expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version2+json")
32
- # end
33
- end
34
- describe "Post operations" do
35
-
36
- # Post
37
- it "Service should return 200 for post" do
38
- post '/ok'
39
- expect(last_response.status).to eq(200)
40
- expect(last_response.body).to eq("success")
41
- expect(last_response.headers['Content-Type']).to eq("application/json")
42
26
  end
27
+ describe "Post operations" do
28
+ it "Service should return 200 for post" do
29
+ post '/ok'
30
+ expect(last_response.status).to eq(200)
31
+ expect(last_response.body).to eq("success")
32
+ expect(last_response.headers['Content-Type']).to eq("application/json")
33
+ end
34
+
35
+ it "Service should return 404 without accept defining routing for post" do
36
+ post '/notfound'
37
+ expect(last_response.status).to eq(404)
38
+ expect(last_response.body).to eq("Not Found")
39
+ expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version+json")
40
+ end
43
41
 
44
- it "Service should return 404 without accept defining routing for post" do
45
- post '/notfound'
46
- expect(last_response.status).to eq(404)
47
- expect(last_response.body).to eq("Not Found")
48
- expect(last_response.headers['Content-Type']).to eq("application/foo.company.product.type-version+json")
49
42
  end
50
-
51
43
  end
52
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_shifter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camilo Ribeiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-16 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -185,8 +185,10 @@ files:
185
185
  - bin/rest_shifter
186
186
  - lib/rest_shifter.rb
187
187
  - lib/rest_shifter/commands.rb
188
+ - lib/rest_shifter/commands/create.rb
188
189
  - lib/rest_shifter/commands/help.rb
189
190
  - lib/rest_shifter/commands/main.rb
191
+ - lib/rest_shifter/commands/start.rb
190
192
  - lib/rest_shifter/commands/version.rb
191
193
  - lib/rest_shifter/shifter.rb
192
194
  - lib/rest_shifter/version.rb