Class: Spider::AppServerClient

Inherits:
Object
  • Object
show all
Defined in:
lib/spiderfw/setup/app_server_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ AppServerClient

Returns a new instance of AppServerClient.



11
12
13
# File 'lib/spiderfw/setup/app_server_client.rb', line 11

def initialize(url)
    @url = url
end

Instance Method Details

#fetch_app(app_id, branch = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/spiderfw/setup/app_server_client.rb', line 60

def fetch_app(app_id, branch=nil)
    tmp = Tempfile.new("spider-app-archive")
    tmp.binmode
    url = @url+"/pack/#{app_id}"
    url += "?branch=#{branch}" if branch
    res = http_get(url)
    tmp << res
    tmp.flush
    tmp.path
end

#get_deps(app_ids, options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/spiderfw/setup/app_server_client.rb', line 50

def get_deps(app_ids, options={})
    app_ids = [app_ids] unless app_ids.is_a?(Array)
    url = "#{@url}/deps/#{app_ids.join('+')}.json"
    params = []
    params << 'no_optional=true' if options[:no_optional]
    url += '?'+params.join('&') unless params.empty?
    result = http_get(url)
    JSON.parse(result).map{ |app| Spider::App::AppSpec.parse_hash(app) }
end

#get_specs(app_ids) ⇒ Object



43
44
45
46
47
48
# File 'lib/spiderfw/setup/app_server_client.rb', line 43

def get_specs(app_ids)
    app_ids = [app_ids] unless app_ids.is_a?(Array)
    url = @url+"/list/#{app_ids.join('+')}.json"
    result = http_get(url)
    JSON.parse(result).map{ |app| Spider::App::AppSpec.parse_hash(app) }
end

#http_get(url) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/spiderfw/setup/app_server_client.rb', line 20

def http_get(url)
    uri = URI.parse(url)
    proxy = uri.find_proxy
    klass = nil
    if proxy
        proxy_user, proxy_pass = nil
        proxy_user, proxy_pass = proxy.userinfo.split(/:/) if proxy.userinfo
        klass = Net::HTTP::Proxy(proxy.host, proxy.port, proxy_user, proxy_pass)
    else
        klass = Net::HTTP
    end
    result = klass.get_response(uri)
    raise "#{result.code} #{result.message} #{uri}" if result.is_a?(Net::HTTPClientError)
    result.body
end

#load_specsObject



36
37
38
39
40
41
# File 'lib/spiderfw/setup/app_server_client.rb', line 36

def load_specs
    url = @url+'/list.json'
    result = http_get(url)
    list = JSON.parse(result)
    @specs = list.map{ |app| Spider::App::AppSpec.parse_hash(app) }
end

#specs(branch = nil) ⇒ Object



15
16
17
18
# File 'lib/spiderfw/setup/app_server_client.rb', line 15

def specs(branch=nil)
    load_specs unless @specs
    @specs
end