Module: Billogram::Endpoint::ClassMethods

Defined in:
lib/billogram/endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_search_optionsObject



21
22
23
# File 'lib/billogram/endpoint.rb', line 21

def default_search_options
  @default_search_options ||= { page: 1, page_size: 50 }
end

Instance Method Details

#create(attributes) ⇒ Object



39
40
41
# File 'lib/billogram/endpoint.rb', line 39

def create(attributes)
  perform_request(:post, "#{endpoint}", attributes)
end

#endpoint(value = nil) ⇒ Object



25
26
27
28
# File 'lib/billogram/endpoint.rb', line 25

def endpoint(value = nil)
  @endpoint = value if value
  @endpoint || name.demodulize.underscore
end

#fetch(id = nil) ⇒ Object



35
36
37
# File 'lib/billogram/endpoint.rb', line 35

def fetch(id = nil)
  perform_request(:get, "#{endpoint}/#{id}")
end

#perform_request(type, url, params = {}) ⇒ Object



43
44
45
46
# File 'lib/billogram/endpoint.rb', line 43

def perform_request(type, url, params = {})
  response = Request.new(type, url, params).execute
  build_objects(response)
end

#search(options = {}) ⇒ Object



30
31
32
33
# File 'lib/billogram/endpoint.rb', line 30

def search(options = {})
  query = default_search_options.merge(options)
  perform_request(:get, "#{endpoint}", query)
end