Module: PrefabC

Defined in:
lib/prefabc.rb,
lib/prefabc/book.rb,
lib/prefabc/client.rb,
lib/prefabc/entity.rb,
lib/prefabc/account.rb,
lib/prefabc/version.rb,
lib/prefabc/transaction.rb,
lib/prefabc/mixins/updates.rb,
lib/prefabc/abstract_resource.rb,
lib/prefabc/mixins/lists_subresources.rb,
lib/prefabc/mixins/reads_subresources.rb,
lib/prefabc/mixins/creates_subresources.rb

Defined Under Namespace

Modules: CreatesSubresources, ListsSubresources, ReadsSubresources, Updates Classes: AbstractResource, Account, Book, Client, Entity, Transaction

Constant Summary collapse

DEFAULT_SCHEME_AND_AUTHORITY =
'https://api.prefabc.com'.freeze
VERSION =
File.read(File.join(File.dirname(__FILE__), '../../VERSION'))
.split("\n")
.first

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject



29
30
31
# File 'lib/prefabc.rb', line 29

def api_key
  @api_key || raise('No API key given.')
end

.scheme_and_authorityObject

Returns the value of attribute scheme_and_authority.



26
27
28
# File 'lib/prefabc.rb', line 26

def scheme_and_authority
  @scheme_and_authority
end

Class Method Details

.create_entity(params) ⇒ Object



55
56
57
58
# File 'lib/prefabc.rb', line 55

def create_entity(params)
  client = Client.new(Entity.new.collection_path)
  Entity.new(client.post(params))
end

.entitiesObject



45
46
47
48
# File 'lib/prefabc.rb', line 45

def entities
  client = Client.new(Entity.new.collection_path)
  client.get.map { |raw_params| Entity.new(raw_params) }
end

.entity(id) ⇒ Object



50
51
52
53
# File 'lib/prefabc.rb', line 50

def entity(id)
  client = Client.new("#{Entity.new.collection_path}/#{id}")
  Entity.new(client.get)
end

.load_config_from_dotfileObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/prefabc.rb', line 33

def load_config_from_dotfile
  config_filepath = ENV['HOME'] + '/.prefabc'
  return unless File.exist?(config_filepath)

  config = IniParse.parse(File.read(config_filepath))
  default_config = config['default']
  return unless default_config

  @scheme_and_authority = default_config['scheme_and_authority']
  @api_key = default_config['api_key']
end