Class: Firebrew::AmoApi::Search

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/firebrew/amo_api/search.rb

Defined Under Namespace

Classes: Format

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fetch(params = {}) ⇒ Object



31
32
33
# File 'lib/firebrew/amo_api/search.rb', line 31

def self.fetch(params={})
  self.find(:all, from: self.path(params)).to_a
end

.fetch!(params = {}) ⇒ Object



35
36
37
38
39
# File 'lib/firebrew/amo_api/search.rb', line 35

def self.fetch!(params={})
  results = self.fetch(params)
  raise Firebrew::ExtensionNotFoundError if results.empty?
  results
end

.path(params = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/firebrew/amo_api/search.rb', line 19

def self.path(params={})
  path_source = '/ja/firefox/api/%{api_version}/search/%{term}/%{type}/%{max}/%{os}/%{version}'
  default_params = {
    api_version: 1.5,
    type: 'all',
    max: 30,
    os: 'all',
    version: '',
  }
  URI.encode(path_source % default_params.merge(params))
end

Instance Method Details

#extensionObject



41
42
43
44
45
46
47
48
# File 'lib/firebrew/amo_api/search.rb', line 41

def extension
  Firebrew::Firefox::BasicExtension.new(
    name: self.name,
    guid: self.guid,
    uri: self.install,
    version: self.version
  )
end