class Harvest::Client
Harvest
client interface
Attributes
active_user[R]
client[R]
factory[R]
state[R]
time_entries[R]
Public Class Methods
new(config, state: { filtered: {} })
click to toggle source
@param config [Struct::Config] Configuration Struct which provides attributes @param state [Hash] State of the Client
for FluentAPI
# File lib/harvest.rb, line 38 def initialize(config, state: { filtered: {} }) @config = config @client = Harvest::HTTP::Api.new(**@config) @factory = Harvest::ResourceFactory.new @state = state @admin_api = if active_user.is_admin config.admin_api else false end end
Public Instance Methods
allowed?(meth)
click to toggle source
# File lib/harvest.rb, line 54 def allowed?(meth) %i[ projects project_tasks time_entry tasks ].include?(meth) end
change(**kwargs)
click to toggle source
Find single instance of resource
# File lib/harvest.rb, line 99 def change(**kwargs) @state[@state[:active]].map do |_obj| Harvest::Changers.const_get(to_class_name(@state[:active])).new.change( @factory, @client, active_user, @state, kwargs ) end self end
clone()
click to toggle source
# File lib/harvest.rb, line 63 def clone Harvest::Client.new(@config, state: @state.clone) end
create(**kwargs)
click to toggle source
Create
an instance of object based on state
# File lib/harvest.rb, line 120 def create(**kwargs) @state[@state[:active]] = Harvest::Create.const_get( to_class_name(@state[:active]) ).new.create( @factory, @client, active_user, @state, kwargs ) self end
data()
click to toggle source
Return data from the active state in the base state or filtered.
# File lib/harvest.rb, line 141 def data @state[@state[:active]] end
discover(**params)
click to toggle source
Discover resources
# File lib/harvest.rb, line 109 def discover(**params) @state[@state[:active]] = Harvest::Discovers .const_get(to_class_name(@state[:active])) .new .discover( @admin_api, @client, @factory, active_user, @state, params ) self end
find(id)
click to toggle source
Find single instance of resource
# File lib/harvest.rb, line 91 def find(id) @state[@state[:active]] = Harvest::Finders.const_get( to_class_name(@state[:active]) ).new.find(@factory, @client, id) self end
map(&block)
click to toggle source
Map block of filtered items
# File lib/harvest.rb, line 136 def map(&block) @state[@state[:active]].map(&block) end
method_missing(meth, *args)
click to toggle source
@param meth [Symbol] @param *args [Array] arguments passed to method.
Calls superclass method
# File lib/harvest.rb, line 75 def method_missing(meth, *args) if allowed?(meth) Harvest::Client.new( @config, state: merge_state(@state, meth, args) ) else super end rescue NoMethodError # require 'pry'; binding.pry raise Harvest::Exceptions::BadState, "#{meth} is an invalid state change." end
respond_to_missing?(meth)
click to toggle source
@param meth [Symbol] @return [Boolean]
# File lib/harvest.rb, line 69 def respond_to_missing?(meth) allowed?(meth) end
select(&block)
click to toggle source
Select a subset of all items depending on state
# File lib/harvest.rb, line 130 def select(&block) @state[@state[:active]] = @state[@state[:active]].select(&block) self end