Class: JobsApiGem

Inherits:
Object
  • Object
show all
Defined in:
lib/jobs_api_gem.rb,
lib/jobs_api_gem/binary.rb,
lib/jobs_api_gem/version.rb

Defined Under Namespace

Classes: Binary

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ JobsApiGem

Returns a new instance of JobsApiGem.



8
9
10
11
12
13
14
15
16
17
# File 'lib/jobs_api_gem.rb', line 8

def initialize(endpoint)
  @ruby_connection  = Faraday.new(url: "https://jobs.github.com/positions.json?postion=ruby")
  @ruby_on_rails_connection  = Faraday.new(url: "https://jobs.github.com/positions.json?postion=ruby+on+rails")
  @javascript_connection  = Faraday.new(url: "https://jobs.github.com/positions.json?postion=javascript")
  @post_connection = Faraday.new(url: "http://localhost:3000")
  @jobs = []
  @posted_jobs = 0
  @endpoint = endpoint
  @search_terms = [@ruby_connection, @ruby_on_rails_connection, @javascript_connection]
end

Instance Method Details

#get_data(term) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jobs_api_gem.rb', line 26

def get_data(term)
  connection = term
  response = connection.get
  body = response.body
  rbody = JSON.parse(body, quirks_mode: true)
  rbody.each_with_index do |job, i|
    job = {
      company: job["company"],
      location: job["location"],
      description: job["description"],
      url: job["url"],
      posting_date: job["created_at"]
    }
    @jobs << job
    puts "Job #{i + 1} pulled."
  end
  if term == @ruby_connection
    puts "Pulled Ruby job summaries"
  elsif term == @ruby_on_rails_connection
    puts "Pulled Ruby on Rails job summaries"
  else
    puts "Pulled JavaScript job summaries"
  end
  send_to_server
end

#iterate_search_termsObject



20
21
22
23
24
# File 'lib/jobs_api_gem.rb', line 20

def iterate_search_terms
  @search_terms.each do |term|
    get_data(term)
  end
end

#send_to_serverObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jobs_api_gem.rb', line 52

def send_to_server
  @jobs.each_with_index do |job, i|
    new_job = {
      location: job[:location],
      description: job[:description],
      source: job[:url],
      position: 'n/a',
    }
    response = @post_connection.post(@endpoint, job: new_job)
  end
end