castle 0.0.1 → 0.0.2

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.
@@ -2,10 +2,29 @@ module Castle
2
2
  class Request
3
3
  METHODS = [:get, :put, :post, :delete, :head, :options]
4
4
 
5
- attr_accessor :method
5
+ attr_accessor :method, :response
6
6
 
7
- def initialize method, url, *query
8
- @method = METHODS.include?(method) ? method : :get
7
+ @@default_method = :get
8
+
9
+ def initialize method, uri, *query
10
+ @method = METHODS.include?(method) ? method : @@default_method
11
+ @uri = URI.parse(uri.include?("http://") ? "#{uri}" : "http://#{uri}")
12
+ @query = {:hash => query[0], :string => ""}
13
+
14
+ i = 0; @query[:hash].to_a.flatten.each {|q| @query[:string] += q.to_s + ((i%2 == 1) ? "&" : "="); i += 1}; @query[:string].chomp! "&"
15
+
16
+ if !@query[:string].empty?
17
+ @query[:string] = URI.encode @query[:string]
18
+ @uri.query = @query[:string] if !@query[:string].empty?
19
+ end
20
+
21
+ args = case @method
22
+ when :get then [@uri.to_s]
23
+ when :post then [@uri.path, @uri.query]
24
+ # TODO: add rest of methods
25
+ end
26
+
27
+ @response = Response.new Net::HTTP.new(@uri.host).send(@method, *args)
9
28
  end
10
29
  end
11
30
  end
@@ -0,0 +1,9 @@
1
+ module Castle
2
+ class Response
3
+ attr_reader :body
4
+
5
+ def initialize response
6
+ @body = response.body
7
+ end
8
+ end
9
+ end
data/lib/castle.rb CHANGED
@@ -1,11 +1,11 @@
1
- %w[net/http uri castle/request].each {|lib| require lib}
1
+ %w[net/http uri castle/request castle/response].each {|lib| require lib}
2
2
 
3
3
  module Castle
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
 
6
6
  Request::METHODS.each do |method|
7
- define_method method do |url, *query|
8
- Request.new method, url, *query
7
+ define_method method do |uri, *query|
8
+ Request.new method, uri, *query
9
9
  end
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: castle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Zachary Adam Kaplan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-10 00:00:00 -07:00
18
+ date: 2010-06-14 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -63,6 +63,7 @@ extra_rdoc_files: []
63
63
 
64
64
  files:
65
65
  - lib/castle/request.rb
66
+ - lib/castle/response.rb
66
67
  - lib/castle.rb
67
68
  - LICENSE
68
69
  - README.md