Module: InklingApi::Connection

Included in:
InklingApi
Defined in:
lib/inkling_api.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/inkling_api.rb', line 43

def connection
  raise "set_url first" unless @url
  @connection ||= begin
    conn = Faraday.new(@url) do |b|
      b.use Faraday::Request::UrlEncoded
      b.use FaradayStack::ResponseJSON, content_type: 'application/json'
      b.use FaradayMiddlewares::ResponseXMLToHash, content_type: 'application/xml'
      b.use PreserveRawBody
      #b.use FaradayStack::Caching, cache, strip_params: %w[access_token client_id] unless cache.nil?
      #b.response :raise_error
      #b.use Faraday::Response::Logger
      b.use FaradayStack::Instrumentation
      b.adapter Faraday.default_adapter
      b.use Mashify
    end

    conn.basic_auth(@login, @password)

    conn
  end
end

#delete(path, params = nil) ⇒ Object



89
90
91
# File 'lib/inkling_api.rb', line 89

def delete(path, params = nil)
  connection.delete(path)
end

#get(path, params = nil) ⇒ Object



65
66
67
68
69
# File 'lib/inkling_api.rb', line 65

def get(path, params = nil)
  connection.get(path) do |request|
    request.params = params if params
  end
end

#login=(login) ⇒ Object



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

def login=()
  @login = 
end

#password=(password) ⇒ Object



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

def password=(password)
  @password = password
end

#post(path, payload, params = nil) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/inkling_api.rb', line 71

def post(path, payload, params = nil)
  connection.post do |request|
    request.url path
    request.headers['Content-Type'] = 'application/xml'
    request.body = payload
    request.params if params
  end
end

#publish(path, params = nil) ⇒ Object



93
94
95
# File 'lib/inkling_api.rb', line 93

def publish(path, params = nil)
  connection.post(path)
end

#put(path, payload, params = nil) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/inkling_api.rb', line 80

def put(path, payload, params = nil)
  connection.put do |request|
    request.url path
    request.headers['Content-Type'] = 'application/xml'
    request.body = payload
    request.params if params
  end
end

#refund(path, params = nil) ⇒ Object



97
98
99
# File 'lib/inkling_api.rb', line 97

def refund(path, params = nil)
  connection.post(path)
end

#url=(url) ⇒ Object



31
32
33
# File 'lib/inkling_api.rb', line 31

def url=(url)
  @url = url
end