findwork_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 297def97752fe43d7998b2e9d1c3ab294fbb4f16a11263368b2f86075f022fab
4
+ data.tar.gz: d7a7034318c7beb0b5e976301598bf4e04e831cb33e9b47825e344f721e00848
5
+ SHA512:
6
+ metadata.gz: 8c8a41f27b1879a3a0e15ae8a047d48ac9c19729d8ddbb4a79f80b5139b12ffd7253a4cbb7c4a22756bea13ffcc33195e1b4b99ad91064feaa166833a7f21524
7
+ data.tar.gz: 34baa252b9588ff9e4a5e5c22a9309ed048b4f6a6238e6357a019b6f510feb74670e2dbed7ebf2e98222c9b5918193fb9df582e46b6016beb2ab1199eaa9bf9f
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Changelog
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # FindworkApi
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/findwork_api`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ client = FindworkApi::Client.new(api_key: ENV["FINDWORK_API_KEY"])
27
+ jobs = client.jobs.list
28
+ jobs.first.name
29
+ ```
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/findwork_api.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
5
+
6
+ require "rake/testtask"
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.libs << "test"
10
+ t.libs << "lib"
11
+ t.test_files = FileList['test/**/*_test.rb']
12
+ t.verbose = true
13
+ end
14
+
15
+ task default: :test
@@ -0,0 +1,28 @@
1
+ require "faraday"
2
+
3
+ module FindworkApi
4
+ class Client
5
+ BASE_URL = "https://findwork.dev/api/"
6
+
7
+ attr_reader :api_key, :adapter
8
+
9
+ def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
10
+ @api_key = api_key
11
+ @adapter = adapter
12
+ @stubs = stubs
13
+ end
14
+
15
+ def connection
16
+ @connection ||= Faraday.new do |conn|
17
+ conn.url_prefix = BASE_URL
18
+ conn.request :json
19
+ conn.response :json, content_type: "application/json"
20
+ conn.adapter adapter, @stubs
21
+ end
22
+ end
23
+
24
+ def jobs
25
+ JobsResource.new(self)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ module FindworkApi
2
+ class Collection
3
+ attr_reader :count, :next_page, :previous_page, :data
4
+
5
+ def self.from_response(response, key:, type:)
6
+ body = response.body
7
+ # Nested values can be appended as additional arguments to dig
8
+ new(
9
+ count: body.dig("count"),
10
+ next_page: body.dig("next"),
11
+ previous_page: body.dig("previous"),
12
+ data: body[key].map { |attrs| type.new(attrs) }
13
+ )
14
+ end
15
+
16
+ def initialize(count:, next_page:, previous_page:, data:)
17
+ @count = count
18
+ @next_page = next_page.nil? ? nil : next_page
19
+ @previous_page = previous_page.nil? ? nil : previous_page
20
+ @data = data
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,3 @@
1
+ module FindworkApi
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,18 @@
1
+ require "ostruct"
2
+
3
+ module FindworkApi
4
+ class Object
5
+ def initialize(attributes)
6
+ @attributes = OpenStruct.new(attributes)
7
+ end
8
+
9
+ def method_missing(method, *args, &block)
10
+ attribute = @attributes.send(method, *args, &block)
11
+ attribute.is_a?(Hash) ? Object.new(attribute) : attribute
12
+ end
13
+
14
+ def respond_to_missing?(method, include_private = false)
15
+ true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module FindworkApi
2
+ class Job < Object
3
+ end
4
+ end
@@ -0,0 +1,40 @@
1
+ module FindworkApi
2
+ class Resource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def get_request(url, params: {}, headers: {})
10
+ handle_response(client.connection.get(url, params, default_headers.merge(headers)))
11
+ end
12
+
13
+ def default_headers
14
+ { Authorization: "Token #{client.api_key}" }
15
+ end
16
+
17
+ def handle_response(response)
18
+ message = (response.body || {})["error"]
19
+
20
+ case response.status
21
+ when 400
22
+ raise Error, message
23
+ when 401
24
+ raise Error, message
25
+ when 403
26
+ raise Error, message
27
+ when 404
28
+ raise Error, message
29
+ when 422
30
+ raise Error, message
31
+ when 429
32
+ raise Error, message
33
+ when 500
34
+ raise Error, message
35
+ end
36
+
37
+ response
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,22 @@
1
+ module FindworkApi
2
+ class JobsResource < Resource
3
+ def list(search: nil, source: nil, location: nil, remote: nil, employees: nil, employment_type: nil, order_by: nil)
4
+ # TODO: Add pagination (in Collection)
5
+ Collection.from_response(get_request("jobs/",
6
+ params: {
7
+ search: search,
8
+ source: source,
9
+ location: location,
10
+ remote: remote,
11
+ company_num_employees: employees,
12
+ employment_type: employment_type,
13
+ order_by: order_by
14
+ }.compact
15
+ ), key: "results", type: Job)
16
+ end
17
+
18
+ def find(id)
19
+ Job.new get_request("jobs/#{id}", params: params)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FindworkApi
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "findwork_api/version"
4
+
5
+ module FindworkApi
6
+ autoload :Client, "findwork_api/client"
7
+ autoload :Collection, "findwork_api/collection"
8
+ autoload :Error, "findwork_api/error"
9
+ autoload :Object, "findwork_api/object"
10
+ autoload :Resource, "findwork_api/resource"
11
+
12
+ autoload :Job, "findwork_api/objects/job"
13
+
14
+ autoload :JobsResource, "findwork_api/resources/jobs"
15
+ end
@@ -0,0 +1,4 @@
1
+ module FindworkApi
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: findwork_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ian Johnson
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.13'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.13'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ostruct
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: minitest
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.0'
54
+ description: A client for interacting with the Findwork API
55
+ email:
56
+ - tacoda@hey.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - CHANGELOG.md
62
+ - README.md
63
+ - Rakefile
64
+ - lib/findwork_api.rb
65
+ - lib/findwork_api/client.rb
66
+ - lib/findwork_api/collection.rb
67
+ - lib/findwork_api/error.rb
68
+ - lib/findwork_api/object.rb
69
+ - lib/findwork_api/objects/job.rb
70
+ - lib/findwork_api/resource.rb
71
+ - lib/findwork_api/resources/jobs.rb
72
+ - lib/findwork_api/version.rb
73
+ - sig/findwork_api.rbs
74
+ homepage: https://github.com/tacoda/findwork_api
75
+ licenses: []
76
+ metadata:
77
+ homepage_uri: https://github.com/tacoda/findwork_api
78
+ source_code_uri: https://github.com/tacoda/findwork_api
79
+ changelog_uri: https://github.com/tacoda/findwork_api/blob/main/CHANGELOG.md
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.1.0
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.6.9
95
+ specification_version: 4
96
+ summary: A gem for the Findwork API
97
+ test_files: []