runcible 0.0.3 → 0.0.4

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.
data/lib/runcible/base.rb CHANGED
@@ -35,10 +35,16 @@ module Runcible
35
35
  # :password Password for this user
36
36
  # :oauth Oauth credentials
37
37
  # :headers Additional headers e.g. content-type => "application/json"
38
+ # :url Scheme and hostname for the pulp server e.g. https://localhost/
39
+ # :api_path URL path for the api e.g. pulp/api/v2/
38
40
  def self.config=(conf={})
39
41
  @@config = {
40
- :headers => { :content_type => 'application/json',
41
- :accept => 'application/json'}
42
+ :api_path => '/pulp/api/v2/',
43
+ :url => 'https://localhost',
44
+ :user => '',
45
+ :http_auth => {:password => {} },
46
+ :headers => {:content_type => 'application/json',
47
+ :accept => 'application/json'}
42
48
  }.merge(conf)
43
49
  end
44
50
 
@@ -47,20 +53,23 @@ module Runcible
47
53
  end
48
54
 
49
55
  def self.call(method, path, options={})
50
- path = '/pulp/api/v2/' + path
56
+ path = config[:api_path] + path
51
57
 
52
- headers = options[:headers] ? options[:headers] : {}
58
+ headers = config[:headers]
53
59
  headers[:params] = options[:params] if options[:params]
54
- headers = add_oauth_header(method, path, headers) if config[:oauth]
55
- headers["pulp-user"] = "admin"#config[:user]
56
60
 
57
- payload = [:post, :put].include?(method) ? generate_payload(options) : {}
61
+ if config[:oauth]
62
+ headers = add_oauth_header(method, path, headers) if config[:oauth]
63
+ headers["pulp-user"] = config[:user]
64
+ client = RestClient::Resource.new(config[:url])
65
+ else
66
+ client = RestClient::Resource.new(config[:url], :user => config[:user], :password => config[:http_auth][:password])
67
+ end
58
68
 
59
69
  args = [method]
60
- args << payload.to_json if [:post, :put].include?(method)
61
- args << headers if headers
70
+ args << generate_payload(options) if [:post, :put].include?(method)
71
+ args << headers
62
72
 
63
- client = RestClient::Resource.new(config[:url], config)
64
73
  process_response(client[path].send(*args))
65
74
  end
66
75
 
@@ -81,7 +90,7 @@ module Runcible
81
90
  payload = {}
82
91
  end
83
92
 
84
- return payload
93
+ return payload.to_json
85
94
  end
86
95
 
87
96
  def self.process_response(response)
@@ -109,6 +118,10 @@ module Runcible
109
118
  return local_names
110
119
  end
111
120
 
121
+ def self.add_http_auth_header
122
+ return {:user => config[:user], :password => config[:http_auth][:password]}
123
+ end
124
+
112
125
  def self.add_oauth_header(method, path, headers)
113
126
  default_options = { :site => config[:url],
114
127
  :http_method => method,
@@ -21,8 +21,6 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
- require 'runcible/base'
25
-
26
24
 
27
25
  module Runcible
28
26
  module Pulp
@@ -1,3 +1,3 @@
1
1
  module Runcible
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end