Module: Rhohub

Defined in:
lib/build/rhohub/rhohub.rb,
lib/build/rhohub/version.rb

Defined Under Namespace

Classes: App, Base, Build, Subscription, Token

Constant Summary collapse

VERSION =
"1.1"
@@requester =
nil
@@token =
nil
@@url =
nil
@@cert_store =
nil

Class Method Summary collapse

Class Method Details

.cert_storeObject



7
8
9
# File 'lib/build/rhohub/rhohub.rb', line 7

def self.cert_store
  @@cert_store
end

.cert_store=(store) ⇒ Object



11
12
13
14
# File 'lib/build/rhohub/rhohub.rb', line 11

def self.cert_store=(store)
  @@cert_store = store
  @@requester = nil
end

.default_request(need_token = true) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/build/rhohub/rhohub.rb', line 70

def self.default_request(need_token = true)
  request = {
      :open_timeout => 5,
      :headers => { :content_type => :json, :accept => :json }
  }

  if @@cert_store
    request[:ssl_cert_store] = @@cert_store
  end

  # FIXME: it is a sslv3 issue https://github.com/nahi/httpclient/issues/202
  request[:ssl_version] = :SSLv23

  if need_token
    request[:headers][:AUTHORIZATION] = Rhohub.token
  end

  request
end

.requester(need_token = true) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/build/rhohub/rhohub.rb', line 90

def self.requester(need_token = true)
  unless need_token
    return RestClient::Resource.new(@@url, default_request(need_token))
  end

  if @@requester.nil?
    @@requester = RestClient::Resource.new(@@url, default_request)
  end

  @@requester
end

.resource_url(options = {}, resource) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/build/rhohub/rhohub.rb', line 46

def self.resource_url(options = {},resource)
  base_url = ''
  case resource
  when 'apps'
    base_url += "/apps" if options.empty? #POST, INDEX
    base_url +=  "/apps/#{options[:app_id]}" if options.has_key?(:app_id) # DELETE, SHOW
  when 'platforms'
    base_url += "/platforms"
  when 'subscription'
    base_url += '/subscription'
  when 'token'
    base_url += '/token'
  when 'supported_gems'
    base_url += '/build/supported_gems'
  when 'user_status'
    base_url += '/build/user_status'
  else
    base_url += "/app/#{options[:app_id]}/builds" if options.has_key?(:app_id) && !options.has_key?(:id) # POST, INDEX
    base_url += "/app/#{options[:app_id]}/builds/#{options[:id]}"  if options.has_key?(:id) && options.has_key?(:app_id) # DELETE, SHOW                  
  end
  base_url
end

.tokenObject



25
26
27
28
29
30
31
# File 'lib/build/rhohub/rhohub.rb', line 25

def self.token
  if @@token
    @@token
  else
    raise "You must set your rhohub api token see README file"
  end
end

.token=(token) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/build/rhohub/rhohub.rb', line 16

def self.token=(token)
  if token
    @@token = token
    @@requester = nil
  else
    raise "Invalid token"
  end
end

.urlObject



33
34
35
# File 'lib/build/rhohub/rhohub.rb', line 33

def self.url
  @@url
end

.url=(url) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/build/rhohub/rhohub.rb', line 37

def self.url=(url)
  if url
    @@url = url
    @@requester = nil
  else
    raise "Invalid url"
  end
end