Skip to content

Commit

Permalink
added public resource FrederickAPI::V2::BusinessCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Severs committed Sep 5, 2017
1 parent d077c13 commit 491d50e
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ to configure the Frederick API client.
...
FrederickAPI.configure do |c|
c.base_url = 'https://api.hirefrederick.com'
c.public_base_url = 'https://api.public.hirefrederick.com'
c.api_key = '1234-5678-1234-5678-1234-5678'
end
...
```

Environment variables can also be used:
* `FREDERICK_API_BASE_URL`: Same as `base_url` above
* `FREDERICK_API_PUBLIC_BASE_URL`: Same as `public_base_url` above
* `FREDERICK_API_KEY`: Same as `api_key` above

Environments:
* For testing (default), use `FREDERICK_API_BASE_URL = https://api.staging.hirefrederick.com`
and `FREDERICK_API_PUBLIC_BASE_URL = https://api.public.staging.hirefrederick.com`
* For production, use `FREDERICK_API_BASE_URL = https://api.hirefrederick.com`

NOTE: You must specify the production base URL of `https://api.hirefrederick.com` in order to use this gem with
Expand Down
4 changes: 4 additions & 0 deletions lib/frederick_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
require 'frederick_api/v2/helpers/query_builder'
require 'frederick_api/v2/helpers/requestor'
require 'frederick_api/v2/resource'
require 'frederick_api/v2/public_resource'

require 'frederick_api/v2/user'
require 'frederick_api/v2/location'

# Public resources
require 'frederick_api/v2/business_category'

# Froldoex resources
require 'frederick_api/v2/contact'
require 'frederick_api/v2/contact_property'
Expand Down
5 changes: 4 additions & 1 deletion lib/frederick_api/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ class Configuration
DEFAULTS = {
base_url: ENV['FREDERICK_API_BASE_URL'] ||
'https://api.staging.hirefrederick.com',
public_base_url: ENV['FREDERICK_API_PUBLIC_BASE_URL'] ||
'https://api.public.staging.hirefrederick.com',
api_key: ENV['FREDERICK_API_KEY']
}.freeze

attr_accessor :base_url, :api_key
attr_accessor :base_url, :public_base_url, :api_key

def initialize
@base_url = DEFAULTS[:base_url]
@public_base_url = DEFAULTS[:public_base_url]
@api_key = DEFAULTS[:api_key]
end
end
Expand Down
9 changes: 9 additions & 0 deletions lib/frederick_api/v2/business_category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module FrederickAPI
module V2
# /v2/business_categories
class BusinessCategory < PublicResource
end
end
end
12 changes: 12 additions & 0 deletions lib/frederick_api/v2/public_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module FrederickAPI
module V2
# Class from which Frederick V2 PUBLIC Resources inherit
class PublicResource < Resource
def self.site
"#{top_level_namespace.config.public_base_url}/v2/"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/frederick_api/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module FrederickAPI
# Current gem version
VERSION = '0.1.7'
VERSION = '0.2.0'
end
8 changes: 8 additions & 0 deletions spec/frederick_api/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module FrederickAPI
RSpec.describe Configuration do
let(:example_base_url) { 'https://api.fakefrederick.example.com' }
let(:example_public_base_url) { 'https://api.public.fakefrederick.example.com' }
let(:example_api_key) { '1234-4567-1234-5678' }
let!(:prev_config) { FrederickAPI.config.dup }

Expand All @@ -14,6 +15,7 @@ module FrederickAPI
before do
FrederickAPI.configure do |c|
c.base_url = example_base_url
c.public_base_url = example_public_base_url
c.api_key = example_api_key
end
end
Expand All @@ -22,9 +24,15 @@ module FrederickAPI
expect(FrederickAPI.config.base_url).to eq example_base_url
end

it 'sets @public_base_url' do
expect(FrederickAPI.config.public_base_url).to eq example_public_base_url
end

it 'sets @api_key' do
expect(FrederickAPI.config.api_key).to eq '1234-4567-1234-5678'
end
end
end

# TODO: backfill specs for ENV-based defaults
end
9 changes: 9 additions & 0 deletions spec/frederick_api/v2/business_category_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'spec_helper'

module FrederickAPI::V2
RSpec.describe BusinessCategory do
it_behaves_like 'v2_public_resource'
end
end
22 changes: 22 additions & 0 deletions spec/frederick_api/v2/public_resource_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'spec_helper'

describe FrederickAPI::V2::PublicResource do
let(:subclass) { FrederickAPI::V2::BusinessCategory }
let(:instance) { subclass.new }

describe 'superclass' do
it 'inherits from JsonApiClient::Resource' do
expect(described_class.superclass).to eq FrederickAPI::V2::Resource
end
end

describe '.site' do
context 'config base_url is set' do
it 'is assigned correctly' do
expect(described_class.site).to eq 'http://public.test.host/v2/'
end
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
require 'webmock/rspec'
require 'frederick_api'
require 'support/v2_resource_shared_examples'
require 'support/v2_public_resource_shared_examples'

configuration_proc = proc do |c|
c.base_url = 'http://test.host'
c.public_base_url = 'http://public.test.host'
c.api_key = '1234-5678-8765-4321'
end

Expand Down
9 changes: 9 additions & 0 deletions spec/support/v2_public_resource_shared_examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

RSpec.shared_examples 'v2_public_resource' do
describe 'superclass' do
it 'inherits from Resource' do
expect(described_class.superclass).to be FrederickAPI::V2::PublicResource
end
end
end

0 comments on commit 491d50e

Please sign in to comment.