apex 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce45f0aec4d74e65e47922ac190a3fef79f56eab
4
- data.tar.gz: 6579046109fa9cbaacf4373092d810baec911fc6
3
+ metadata.gz: 24a9d0530a8e0f20a245e5f094cc057e48b3c65c
4
+ data.tar.gz: 92537d8ff5a9b0956defdbfdc322fece2b83ca17
5
5
  SHA512:
6
- metadata.gz: 9c38ee0ee8204bbcb7dc262dd41ffc62c49d4f91845eeee5890cc755f3ebacc12535561aee3a1708307abbd728b742cae5156cc63138afd481772d01815c36d1
7
- data.tar.gz: 0befa085c338f2df86f5fcf12e147562a433482ef9840cbc1f6c92f421bad17d61d50be494f2a542ccbdcaea4bb0d76214ebbb8281e7555aa0c8e1fd644536f6
6
+ metadata.gz: 2bf2408a5939d42e72484144006d4741bb27e48aba9c3f5f5f3be4024cc493041161d7107d767bb00737815cbd17c59dc743619be1fc4699d826eb64b22d11f2
7
+ data.tar.gz: e53dcbb163dbe738a47b06deb491eef898bb3af9da1894c6244cdd7d3a42cf3912c9101aca4a780fa3d2089fef3ec63d9fcfb3ed9371e5aab2baeb322cf743cb
data/README.md CHANGED
@@ -7,11 +7,13 @@ router and DSL.
7
7
  Apex is currently experimental and in development. Let me know
8
8
  what you think [on Twitter](http://twitter.com/jamonholmgren).
9
9
 
10
+ Apex is a research project of [Infinite Red](http://infinite.red), a web and mobile development company based in Portland, OR and San Francisco, CA.
11
+
10
12
  ## Installation
11
13
 
12
14
  ```ruby
13
15
  # In Gemfile:
14
- gem 'apex', :git => 'https://github.com/clearsightstudio/apex.git'
16
+ gem 'apex', :git => 'https://github.com/infinitered/apex.git'
15
17
 
16
18
  # In Terminal:
17
19
  bundle install
@@ -40,6 +42,12 @@ class AppDelegate < Apex::Server
40
42
  "<p><a href='/about'>About Apex</a></p>"
41
43
  end
42
44
 
45
+ # You can send an array and both paths
46
+ # will have the same response
47
+ get ["path1", "path2"] do |r|
48
+ "Path 1 and 2"
49
+ end
50
+
43
51
  get "/about" do |r|
44
52
  "<h1>About Apex</h1>" +
45
53
  "<p><a href='/'>Home</a></p>"
@@ -77,7 +85,7 @@ class AboutController < Apex::Controller
77
85
  def about
78
86
  render :about
79
87
  end
80
-
88
+
81
89
  def me
82
90
  render :me, name: "Jamon"
83
91
  end
@@ -87,7 +95,7 @@ def AboutView < Apex::View
87
95
  def about
88
96
  "<h1>About</h1>"
89
97
  end
90
-
98
+
91
99
  def me(args={})
92
100
  "<h1>Me #{args[:name]}</h1>"
93
101
  end
@@ -102,7 +110,7 @@ def AboutLayout < Apex::Layout
102
110
  "<body>#{content}</body>" +
103
111
  "</html>"
104
112
  end
105
-
113
+
106
114
  # Potentially, a Ruby DSL for HTML:
107
115
  def render
108
116
  html do
@@ -1,3 +1,2 @@
1
1
  module Apex
2
2
  end
3
-
@@ -695,4 +695,4 @@ module Apex
695
695
  end
696
696
 
697
697
  end
698
- end
698
+ end
@@ -103,24 +103,34 @@ module Apex
103
103
 
104
104
  # Class methods *************************
105
105
 
106
- def self.get(path, args={}, &block)
107
- routes[:get][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
106
+ def self.get(paths, args={}, &block)
107
+ Array(paths).each do |path|
108
+ routes[:get][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
109
+ end
108
110
  end
109
111
 
110
- def self.post(path, args={}, &block)
111
- routes[:post][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
112
+ def self.post(paths, args={}, &block)
113
+ Array(paths).each do |path|
114
+ routes[:post][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
115
+ end
112
116
  end
113
117
 
114
- def self.put(path, args={}, &block)
115
- routes[:put][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
118
+ def self.put(paths, args={}, &block)
119
+ Array(paths).each do |path|
120
+ routes[:put][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
121
+ end
116
122
  end
117
123
 
118
- def self.patch(path, args={}, &block)
119
- routes[:patch][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
124
+ def self.patch(paths, args={}, &block)
125
+ Array(paths).each do |path|
126
+ routes[:patch][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
127
+ end
120
128
  end
121
129
 
122
- def self.delete(path, args={}, &block)
123
- routes[:delete][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
130
+ def self.delete(paths, args={}, &block)
131
+ Array(paths).each do |path|
132
+ routes[:delete][path] = { handler: block, layout: args[:layout], response_type: args[:response_type] }
133
+ end
124
134
  end
125
135
 
126
136
  def self.routes
@@ -145,4 +155,4 @@ module Apex
145
155
  end
146
156
 
147
157
  end
148
- end
158
+ end
@@ -1,3 +1,3 @@
1
1
  module Apex
2
- VERSION = "0.1.0" unless defined?(Apex::VERSION)
2
+ VERSION = "0.2.0" unless defined?(Apex::VERSION)
3
3
  end
@@ -41,9 +41,9 @@ describe "Apex::Request GET request" do
41
41
  request.headers.should == headers
42
42
  end
43
43
 
44
- it "#content_length" do
45
- request.content_length.should == 9223372036854775807
46
- end
44
+ # it "#content_length" do
45
+ # request.content_length.should == 9223372036854775807
46
+ # end
47
47
 
48
48
  it "#query" do
49
49
  request.query.should == query
@@ -0,0 +1,107 @@
1
+ describe "Apex::Server" do
2
+
3
+ class BlankServer < Apex::Server
4
+ end
5
+
6
+ class PortServer < Apex::Server
7
+ port 8085
8
+ end
9
+
10
+ class RouteServer < Apex::Server
11
+ get '/test' do |r|
12
+ "response"
13
+ end
14
+ end
15
+
16
+ class MultiRouteServer < Apex::Server
17
+ get ['/test', '/anothertest'] do |r|
18
+ "response"
19
+ end
20
+ end
21
+
22
+ before do
23
+ @blank = BlankServer.new
24
+ @port = PortServer.new
25
+ @route = RouteServer.new
26
+ @multiroute = MultiRouteServer.new
27
+
28
+ @servers = [@blank, @port, @route, @multiroute]
29
+ end
30
+
31
+ after do
32
+ # Stop and delete the servers.
33
+ @servers.each do |s|
34
+ s.stop
35
+ s = nil
36
+ end
37
+ end
38
+
39
+ it "should be a GCDWebServer" do
40
+ @blank.server.is_a?(GCDWebServer).should == true
41
+ end
42
+
43
+ it "should start the server" do
44
+ @blank.server.isRunning.should == false
45
+ @blank.start
46
+ wait 0.5 do
47
+ @blank.server.isRunning.should == true
48
+ end
49
+ end
50
+
51
+ it "should have a default port" do
52
+ @blank.port.should == 8080
53
+ @blank.start
54
+ wait 0.5 do
55
+ @blank.server.port.should == 8080
56
+ end
57
+ end
58
+
59
+ it "should have a customizable port" do
60
+ @port.port.should == 8085
61
+ @port.start
62
+ wait 0.5 do
63
+ @port.server.port.should == 8085
64
+ end
65
+ end
66
+
67
+ it "should have routes" do
68
+ routes = @route.routes[:get]
69
+ routes.is_a?(Hash).should == true
70
+ routes.count.should == 1
71
+
72
+ routes['/test'][:handler].call.should == "response"
73
+ end
74
+
75
+ it "should have multiple routes with the same responder" do
76
+ routes = @multiroute.routes[:get]
77
+ routes.count.should == 2
78
+
79
+ routes['/test'][:handler].call.should == "response"
80
+ routes['/anothertest'][:handler].call.should == "response"
81
+ end
82
+
83
+ # TODO - implement this test. It's failing for some reason because the
84
+ # the response is nil.
85
+
86
+ # it "should serve assets from resources/assets" do
87
+ # url = NSURL.URLWithString("http://localhost:8080/somefile.txt")
88
+ #
89
+ # session = NSURLSession.sharedSession
90
+ # session.dataTaskWithURL(url, completionHandler: -> data, response, error {
91
+ # @response = {
92
+ # string: NSString.alloc.initWithData(data, encoding:NSUTF8StringEncoding),
93
+ # data: data,
94
+ # response: response,
95
+ # erorr: error,
96
+ # }
97
+ # resume
98
+ # }).resume
99
+ #
100
+ # wait do
101
+ # @response[:error].should.be.nil
102
+ # @response[:string].should == "somefile contents\n"
103
+ # @response[:response].statusCode.should == 200
104
+ # end
105
+ # end
106
+
107
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamon Holmgren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-15 00:00:00.000000000 Z
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: motion-cocoapods
@@ -55,6 +55,7 @@ files:
55
55
  - lib/apex/server.rb
56
56
  - lib/apex/version.rb
57
57
  - spec/unit/request_get_spec.rb
58
+ - spec/unit/server_spec.rb
58
59
  homepage: https://github.com/clearsightstudio/apex
59
60
  licenses:
60
61
  - MIT
@@ -75,10 +76,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  version: '0'
76
77
  requirements: []
77
78
  rubyforge_project:
78
- rubygems_version: 2.4.6
79
+ rubygems_version: 2.2.2
79
80
  signing_key:
80
81
  specification_version: 4
81
82
  summary: Apex is a RubyMotion web framework for OS X. It uses GCDWebServer under the
82
83
  hood and provides a Sinatra-like router and DSL.
83
84
  test_files:
84
85
  - spec/unit/request_get_spec.rb
86
+ - spec/unit/server_spec.rb