diff --git a/lib/namely/collection.rb b/lib/namely/collection.rb index 3c93e53..0febaf5 100644 --- a/lib/namely/collection.rb +++ b/lib/namely/collection.rb @@ -71,6 +71,12 @@ def find(id) raise NoSuchModelError, "Can't find any #{endpoint} with id \"#{id}\"" end + def find_from(id, find_from=nil) + resource_gateway.json_find_from(id, find_from).map { |model| build(model) } + rescue RestClient::ResourceNotFound + raise NoSuchModelError, "Can't find any #{endpoint} with id \"#{id}\"" + end + private attr_reader :resource_gateway diff --git a/lib/namely/connection.rb b/lib/namely/connection.rb index 68e0b6b..fe0a5a9 100644 --- a/lib/namely/connection.rb +++ b/lib/namely/connection.rb @@ -50,6 +50,13 @@ def fields collection("profiles/fields") end + # Return a Collection of job tiers. + # + # @return [Collection] + def group_types + collection("group_types") + end + # Return a Collection of job tiers. # # @return [Collection] @@ -78,14 +85,14 @@ def reports collection("reports") end - private - - attr_reader :access_token, :subdomain - def collection(endpoint, options = {}) Namely::Collection.new(gateway(endpoint, options)) end + private + + attr_reader :access_token, :subdomain + def gateway(endpoint, options = {}) ResourceGateway.new(options.merge( access_token: access_token, diff --git a/lib/namely/resource_gateway.rb b/lib/namely/resource_gateway.rb index f578b51..bad4a9f 100644 --- a/lib/namely/resource_gateway.rb +++ b/lib/namely/resource_gateway.rb @@ -13,6 +13,10 @@ def json_index paged ? json_index_paged : json_index_all end + def json_find_from(id, find_from) + get("/#{endpoint}/#{id}/#{find_from}")[find_from] + end + def json_show(id) get("/#{endpoint}/#{id}")[resource_name].first end diff --git a/lib/namely/version.rb b/lib/namely/version.rb index 57c7498..e277e84 100644 --- a/lib/namely/version.rb +++ b/lib/namely/version.rb @@ -1,3 +1,3 @@ module Namely - VERSION = '0.2.5' + VERSION = '0.2.5.17' end