Class: Kickfire::Company

Inherits:
Object
  • Object
show all
Defined in:
lib/kickfire/company.rb

Constant Summary collapse

BASE_URL =
"https://api.kickfire.com/v2/"
BASE_QUERY =
"company:(all)"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = nil) ⇒ Company

Returns a new instance of Company.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kickfire/company.rb', line 6

def initialize(attributes = nil)
  if attributes.kind_of?(Array) && attributes.first
    attributes = attributes.first
  end

  if attributes.kind_of?(Hash)
    @raw = attributes
    attributes.each do |k,v|
      instance_variable_set("@#{k.to_s.underscore}", v)
    end
  elsif attributes.kind_of? String
    Kickfire::Company.find(attributes)
  end
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



57
58
59
# File 'lib/kickfire/company.rb', line 57

def category
  @category
end

#category2Object (readonly)

Returns the value of attribute category2.



59
60
61
# File 'lib/kickfire/company.rb', line 59

def category2
  @category2
end

#cidObject (readonly)

Returns the value of attribute cid.



44
45
46
# File 'lib/kickfire/company.rb', line 44

def cid
  @cid
end

#cityObject (readonly)

Returns the value of attribute city.



48
49
50
# File 'lib/kickfire/company.rb', line 48

def city
  @city
end

#countryObject (readonly)

Returns the value of attribute country.



53
54
55
# File 'lib/kickfire/company.rb', line 53

def country
  @country
end

#countryShortObject (readonly)

Returns the value of attribute countryShort.



52
53
54
# File 'lib/kickfire/company.rb', line 52

def countryShort
  @countryShort
end

#employeesObject (readonly)

Returns the value of attribute employees.



55
56
57
# File 'lib/kickfire/company.rb', line 55

def employees
  @employees
end

#facebookObject (readonly)

Returns the value of attribute facebook.



64
65
66
# File 'lib/kickfire/company.rb', line 64

def facebook
  @facebook
end

#lattitudeObject (readonly)

Returns the value of attribute lattitude.



62
63
64
# File 'lib/kickfire/company.rb', line 62

def lattitude
  @lattitude
end

#linedkin_idObject (readonly)

Returns the value of attribute linedkin_id.



67
68
69
# File 'lib/kickfire/company.rb', line 67

def linedkin_id
  @linedkin_id
end

#linkedinObject (readonly)

Returns the value of attribute linkedin.



66
67
68
# File 'lib/kickfire/company.rb', line 66

def linkedin
  @linkedin
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



61
62
63
# File 'lib/kickfire/company.rb', line 61

def longitude
  @longitude
end

#naics_codeObject (readonly)

Returns the value of attribute naics_code.



60
61
62
# File 'lib/kickfire/company.rb', line 60

def naics_code
  @naics_code
end

#nameObject (readonly)

Returns the value of attribute name.



45
46
47
# File 'lib/kickfire/company.rb', line 45

def name
  @name
end

#phoneObject (readonly)

Returns the value of attribute phone.



54
55
56
# File 'lib/kickfire/company.rb', line 54

def phone
  @phone
end

#postalObject (readonly)

Returns the value of attribute postal.



51
52
53
# File 'lib/kickfire/company.rb', line 51

def postal
  @postal
end

#regionObject (readonly)

Returns the value of attribute region.



50
51
52
# File 'lib/kickfire/company.rb', line 50

def region
  @region
end

#regionShortObject (readonly)

Returns the value of attribute regionShort.



49
50
51
# File 'lib/kickfire/company.rb', line 49

def regionShort
  @regionShort
end

#revenueObject (readonly)

Returns the value of attribute revenue.



56
57
58
# File 'lib/kickfire/company.rb', line 56

def revenue
  @revenue
end

#site_codeObject (readonly)

Returns the value of attribute site_code.



58
59
60
# File 'lib/kickfire/company.rb', line 58

def site_code
  @site_code
end

#stock_symbolObject (readonly)

Returns the value of attribute stock_symbol.



63
64
65
# File 'lib/kickfire/company.rb', line 63

def stock_symbol
  @stock_symbol
end

#streetObject (readonly)

Returns the value of attribute street.



47
48
49
# File 'lib/kickfire/company.rb', line 47

def street
  @street
end

#twitterObject (readonly)

Returns the value of attribute twitter.



65
66
67
# File 'lib/kickfire/company.rb', line 65

def twitter
  @twitter
end

#websiteObject (readonly)

Returns the value of attribute website.



46
47
48
# File 'lib/kickfire/company.rb', line 46

def website
  @website
end

Class Method Details

.find(ip, api_key: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kickfire/company.rb', line 21

def self.find(ip, api_key: nil)
  if !api_key
    if defined? Kickfire::API_KEY
      api_key = Kickfire::API_KEY
    end
  end

  uri = URI("#{BASE_URL}#{BASE_QUERY}")
  params = { ip: ip, key: api_key }
  uri.query = URI.encode_www_form(params)
  response = ::HTTParty.get(uri)

  if !response
    raise Kickfire::Error.new('No data returned from Kickfire')
  elsif response['status'] == 'error'
    Kickfire::Error.find(response['code'],response['message'])
  elsif response['status'] == 'not found'
    nil
  else
    new(response['data'])
  end
end

Instance Method Details

#addressObject



77
78
79
# File 'lib/kickfire/company.rb', line 77

def address
  [street, city, regionShort, postal].compact.join ", "
end

#isp?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/kickfire/company.rb', line 69

def isp?
  @is_isp == 1
end

#to_jsonObject



81
82
83
# File 'lib/kickfire/company.rb', line 81

def to_json
  @raw.to_json
end

#twitter_urlObject



73
74
75
# File 'lib/kickfire/company.rb', line 73

def twitter_url
  "http://twitter.com/" + twitter
end