restrack-client 0.0.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- restrack-client (0.0.0)
4
+ restrack-client (0.1.4)
5
5
  i18n
6
6
  json
7
7
  mime-types
data/Rakefile CHANGED
@@ -8,5 +8,5 @@ task :default => [:test]
8
8
 
9
9
  desc 'Run tests.'
10
10
  Rake::TestTask.new('test') { |t|
11
- t.pattern = 'test/**/*.rb'
11
+ t.pattern = 'test/test_*.rb'
12
12
  }
@@ -1,3 +1,3 @@
1
1
  module RESTRackClient
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -6,37 +6,37 @@ require 'xmlsimple'
6
6
 
7
7
  module RESTRack
8
8
  class Client
9
-
9
+
10
10
  def initialize(uri, format=:JSON)
11
11
  @uri = URI.parse(uri) unless uri.is_a? URI
12
12
  @path = ''
13
13
  @format = format
14
14
  end
15
-
15
+
16
16
  def method_missing(resource_name, *args)
17
17
  @path << '/' + resource_name.to_s + '/' + args.join('/')
18
18
  self
19
19
  end
20
-
20
+
21
21
  def get
22
22
  request = Net::HTTP::Get.new(@path)
23
23
  response = send request
24
24
  parse response
25
25
  end
26
-
26
+
27
27
  def delete
28
28
  request = Net::HTTP::Delete.new(@path)
29
29
  response = send request
30
30
  parse response
31
31
  end
32
-
32
+
33
33
  def post(data=nil)
34
34
  request = Net::HTTP::Post.new(@path, {'Content-Type' => content_type })
35
35
  request.body = prepare data unless data.nil?
36
36
  response = send request
37
37
  parse response
38
38
  end
39
-
39
+
40
40
  def put(data=nil)
41
41
  request = Net::HTTP::Put.new(@path, {'Content-Type' => content_type })
42
42
  request.body = prepare data unless data.nil?
@@ -48,7 +48,7 @@ module RESTRack
48
48
  def content_type
49
49
  RESTRack.mime_type_for(@format).to_s
50
50
  end
51
-
51
+
52
52
  def prepare(data)
53
53
  case @format
54
54
  when :JSON
@@ -62,7 +62,7 @@ module RESTRack
62
62
  end
63
63
  data
64
64
  end
65
-
65
+
66
66
  def send(request)
67
67
  response = Net::HTTP.start(@uri.host, @uri.port) { |http| http.request(request) }
68
68
  unless response.kind_of?(Net::HTTPSuccess)
@@ -71,7 +71,7 @@ module RESTRack
71
71
  end
72
72
  response
73
73
  end
74
-
74
+
75
75
  def parse(response)
76
76
  mime_type = MIME::Type.new( response.content_type )#response['content-type'] )
77
77
  if mime_type.like?( RESTRack.mime_type_for( :JSON ) )
@@ -85,7 +85,6 @@ module RESTRack
85
85
  end
86
86
  end
87
87
 
88
- # XXX - code smells this is also in RESTRack lib/support.rb
89
88
  module RESTRack
90
89
  def self.mime_type_for(format)
91
90
  MIME::Types.type_for(format.to_s.downcase)[0]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: restrack-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.0
5
+ version: 0.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris St. John
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-26 00:00:00 -05:00
13
+ date: 2011-03-27 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency