Module: CdekApi

Defined in:
lib/cdek_api.rb,
lib/cdek_api/error.rb,
lib/cdek_api/request.rb,
lib/cdek_api/version.rb,
lib/cdek_api/response.rb,
lib/cdek_api/api_request.rb,
lib/generators/cdek_api/install/install_generator.rb

Defined Under Namespace

Classes: APIRequest, DynamicSetting, Error, InstallGenerator, Request, Response

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.add_reader(name) ⇒ Object



28
29
30
31
32
# File 'lib/cdek_api.rb', line 28

def add_reader(name)
  define_singleton_method(name) do |*args|
    send("#{name}_setting").value(*args)
  end
end

.add_writer(name, type) ⇒ Object



34
35
36
37
38
# File 'lib/cdek_api.rb', line 34

def add_writer(name, type)
  define_singleton_method("#{name}=") do |value|
    send("#{name}_setting=", DynamicSetting.build(value, type))
  end
end

.generate_access_token(client_id = CdekApi.client_id, client_secret = CdekApi.client_secret, grant_type = CdekApi.grant_type) ⇒ Object



11
12
13
14
# File 'lib/cdek_api.rb', line 11

def generate_access_token(client_id=CdekApi.client_id, client_secret=CdekApi.client_secret, grant_type=CdekApi.grant_type)
  response = Faraday.post(CdekApi.url_token, "grant_type=#{grant_type}&client_id=#{client_id}&client_secret=#{client_secret}")
  JSON.parse(response.body)
end

.register(name, value, type = nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/cdek_api.rb', line 20

def register(name, value, type = nil)
  cattr_accessor "#{name}_setting".to_sym

  add_reader(name)
  add_writer(name, type)
  send "#{name}=", value
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (CdekApi)

    the object that the method was called on



16
17
18
# File 'lib/cdek_api.rb', line 16

def setup
  yield self
end