stash-client 0.0.9 → 0.1.0

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: f21fe1aca9ec460ae0f48f9e8d935273df6ab12e
4
- data.tar.gz: 76d5ff257df17b8ec7bfad6883df1d055081a787
3
+ metadata.gz: d0bfb9b31c359e4311307f236d66f7753be9345b
4
+ data.tar.gz: c10d90b5ad153f73131e690a336ab4da18320fd8
5
5
  SHA512:
6
- metadata.gz: 92ac8a9115650f4f7a718a0f13033e67ce2b4ddb3c265bf0e1ef27ec7d148422866ebc3dda85edf36b806f83f1df57b9e491c1e22ea3a5238b920422b95f1719
7
- data.tar.gz: 0fa261fd2cb0e25496e20bc6d8f403f4d12b62616a2a2f1e45a67c32d58573758376b0584e43cc37b0d0499860fe80d32ce65fc5c8737e87b90e9f79b0e3e2f8
6
+ metadata.gz: c54a18c9f3743786c8ec168f1b63d403ca1b9ffd22865a140d08592bc1825730e1ea654415795f59c86654be68bc7b391c3d1e3e6aed759a99e80d58903e4819
7
+ data.tar.gz: 485eaa886757e21005c29902a495a36eba19f2cda35c23dd22e5037124fe6cdadbc090b31afb99f827b4dd8890f6f5ffd93ba173f5afd05a6e6dc0c9181ef44b
@@ -1,5 +1,5 @@
1
- require "stash/client/version"
2
- require "restclient"
1
+ require 'stash/client/version'
2
+ require 'faraday'
3
3
  require 'addressable/uri'
4
4
  require 'json'
5
5
 
@@ -9,19 +9,26 @@ module Stash
9
9
  attr_reader :url
10
10
 
11
11
  def initialize(opts = {})
12
- if opts[:host] && opts[:scheme]
13
- @url = Addressable::URI.parse(opts[:scheme] + '://' + opts[:host] + '/rest/api/1.0/')
14
- elsif opts[:host]
15
- @url = Addressable::URI.parse('http://' + opts[:host] + '/rest/api/1.0/')
16
- elsif opts[:url]
17
- @url = Addressable::URI.parse(opts[:url])
18
- elsif opts[:uri] && opts[:uri].kind_of?(Addressable::URI)
19
- @url = opts[:uri]
12
+ if opts[:client]
13
+ @client = opts[:client]
20
14
  else
21
- raise ArgumentError, "must provide :url or :host"
15
+ if opts[:host] && opts[:scheme]
16
+ @url = Addressable::URI.parse(opts[:scheme] + '://' + opts[:host] + '/rest/api/1.0/')
17
+ elsif opts[:host]
18
+ @url = Addressable::URI.parse('http://' + opts[:host] + '/rest/api/1.0/')
19
+ elsif opts[:url]
20
+ @url = Addressable::URI.parse(opts[:url])
21
+ elsif opts[:uri] && opts[:uri].kind_of?(Addressable::URI)
22
+ @url = opts[:uri]
23
+ else
24
+ raise ArgumentError, "must provide :url or :host"
25
+ end
26
+
27
+ @url.userinfo = opts[:credentials] if opts[:credentials]
28
+
29
+ @client = Faraday.new(@url.site)
22
30
  end
23
31
 
24
- @url.userinfo = opts[:credentials] if opts[:credentials]
25
32
  end
26
33
 
27
34
  def projects
@@ -115,27 +122,45 @@ module Stash
115
122
  end
116
123
 
117
124
  def fetch(uri)
118
- parse(RestClient.get(uri.to_s, :accept => :json))
125
+ res = @client.get { |req|
126
+ req.url uri.to_s
127
+ req.headers['Accept'] = 'application/json'
128
+ }
129
+
130
+ parse(res.body)
119
131
  end
120
132
 
121
133
  def post(uri, data)
122
- parse(
123
- RestClient.post(
124
- uri.to_s, data.to_json, :accept => :json, :content_type => :json
125
- )
126
- )
134
+ res = @client.post { |req|
135
+ req.url uri.to_s
136
+ req.body = data.to_json
137
+
138
+ req.headers['Content-Type'] = 'application/json'
139
+ req.headers['Accpet'] = 'application/json'
140
+ }
141
+
142
+ parse(res.body)
127
143
  end
128
144
 
129
145
  def put(uri, data)
130
- parse(
131
- RestClient.put(
132
- uri.to_s, data.to_json, :accept => :json, :content_type => :json
133
- )
134
- )
146
+ res = @client.put { |req|
147
+ req.url uri.to_s
148
+ req.body = data.to_json
149
+
150
+ req.headers['Content-Type'] = 'application/json'
151
+ req.headers['Accpet'] = 'application/json'
152
+ }
153
+
154
+ parse(res.body)
135
155
  end
136
156
 
137
157
  def delete(uri)
138
- RestClient.delete(uri.to_s, :accept => :json)
158
+ res = @client.delete { |req|
159
+ req.url uri.to_s
160
+ req.headers['Accpet'] = 'application/json'
161
+ }
162
+
163
+ res.body
139
164
  end
140
165
 
141
166
  def parse(str)
@@ -1,5 +1,5 @@
1
1
  module Stash
2
2
  class Client
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rspec"
26
26
  spec.add_development_dependency "webmock"
27
27
 
28
- spec.add_dependency 'rest-client'
28
+ spec.add_dependency 'faraday'
29
29
  spec.add_dependency 'addressable'
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stash-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rest-client
70
+ name: faraday
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '>='