Class: PuppetLibrary::Forge::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_library/forge/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, query_cache = PuppetLibrary::Http::Cache::InMemory.new, download_cache = PuppetLibrary::Http::Cache::NoOp.new, http_client = PuppetLibrary::Http::HttpClient.new) ⇒ Proxy

Returns a new instance of Proxy.



25
26
27
28
29
30
31
32
33
# File 'lib/puppet_library/forge/proxy.rb', line 25

def initialize(url,
               query_cache = PuppetLibrary::Http::Cache::InMemory.new,
               download_cache = PuppetLibrary::Http::Cache::NoOp.new,
               http_client = PuppetLibrary::Http::HttpClient.new)
    @url = PuppetLibrary::Http::Url.normalize(url)
    @http_client = http_client
    @query_cache = query_cache
    @download_cache = download_cache
end

Instance Method Details

#get_module_buffer(author, name, version) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/puppet_library/forge/proxy.rb', line 41

def get_module_buffer(author, name, version)
    begin
        version_info = get_module_version(author, name, version)
        raise ModuleNotFound if version_info.nil?
        download_file(version_info["file"])
    rescue OpenURI::HTTPError
        raise ModuleNotFound
    end
end

#get_module_metadata(author, name) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/puppet_library/forge/proxy.rb', line 51

def (author, name)
    begin
        response = get("/#{author}/#{name}.json")
        JSON.parse(response)
    rescue OpenURI::HTTPError
        raise ModuleNotFound
    end
end

#get_module_metadata_with_dependencies(author, name, version) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/puppet_library/forge/proxy.rb', line 60

def (author, name, version)
    begin
        look_up_releases(author, name, version)
    rescue OpenURI::HTTPError
        raise ModuleNotFound
    end
end

#search_modules(query) ⇒ Object



35
36
37
38
39
# File 'lib/puppet_library/forge/proxy.rb', line 35

def search_modules(query)
    query_parameter = query.nil? ? "" : "?q=#{query}"
    results = get("/modules.json#{query_parameter}")
    JSON.parse results
end