Class: Firmapi::Companies

Inherits:
Object
  • Object
show all
Defined in:
lib/firmapi/companies.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, params) ⇒ Companies

Returns a new instance of Companies.



6
7
8
9
10
11
12
13
# File 'lib/firmapi/companies.rb', line 6

def initialize(options, params)
  @results = options["results"]
  @size = options["size"]
  @page = options["page"]
  @number_of_pages = options["number_of_pages"]
  @list = []
  @params = params
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



4
5
6
# File 'lib/firmapi/companies.rb', line 4

def list
  @list
end

#number_of_pagesObject (readonly)

Returns the value of attribute number_of_pages.



4
5
6
# File 'lib/firmapi/companies.rb', line 4

def number_of_pages
  @number_of_pages
end

#pageObject (readonly)

Returns the value of attribute page.



4
5
6
# File 'lib/firmapi/companies.rb', line 4

def page
  @page
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/firmapi/companies.rb', line 4

def params
  @params
end

#resultsObject (readonly)

Returns the value of attribute results.



4
5
6
# File 'lib/firmapi/companies.rb', line 4

def results
  @results
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/firmapi/companies.rb', line 4

def size
  @size
end

Class Method Details

.where(params) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/firmapi/companies.rb', line 29

def self.where(params)

   @params = params

   response = API.new.get '/companies', params

if response.status == 200
	json = response.body

	companies = self.new(json["result"]["search"], params)

     json["result"]["list"].each do |company_info|
       companies.add_company Company.new(company_info)
     end

     companies
end
end

Instance Method Details

#add_company(company) ⇒ Object



15
16
17
# File 'lib/firmapi/companies.rb', line 15

def add_company(company)
  @list << company
end

#next_pageObject



23
24
25
26
27
# File 'lib/firmapi/companies.rb', line 23

def next_page
  params[:page] = page + 1

  Companies.where(params)
end

#to_aObject



19
20
21
# File 'lib/firmapi/companies.rb', line 19

def to_a
  @list
end