Class: PagSeguro::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pagseguro/client.rb', line 10

def initialize(options = {})
  @options = options
  @logger = options.delete(:logger)
  @connection = Faraday.new api_url do |conn|
    conn.request :json
    conn.response :logger, logger, bodies: true if logger
    conn.response :mashify, mash_class: PagSeguro::Mash
    conn.response :xml,  content_type: /\bxml$/
    conn.response :json, content_type: /\bjson$/
    conn.response :raise_error
    conn.adapter :net_http
    conn.params = auth_params
    conn.headers[:accept] = ACCEPTS[:json]
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



8
9
10
# File 'lib/pagseguro/client.rb', line 8

def connection
  @connection
end

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/pagseguro/client.rb', line 8

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/pagseguro/client.rb', line 8

def options
  @options
end

Instance Method Details

#authorizationsObject



42
43
44
# File 'lib/pagseguro/client.rb', line 42

def authorizations
  @authorizations ||= Authorizations.new(self)
end

#checkoutObject



46
47
48
# File 'lib/pagseguro/client.rb', line 46

def checkout
  @checkout ||= Checkout.new(self)
end

#payment_ordersObject



30
31
32
# File 'lib/pagseguro/client.rb', line 30

def payment_orders
  @payment_orders ||= PaymentOrders.new(self)
end

#plansObject



38
39
40
# File 'lib/pagseguro/client.rb', line 38

def plans
  @plans ||= Plans.new(self)
end

#sessionsObject



34
35
36
# File 'lib/pagseguro/client.rb', line 34

def sessions
  @sessions ||= Sessions.new(self)
end

#subscriptionsObject



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

def subscriptions
  @subscriptions ||= Subscriptions.new(self)
end

#transactionsObject



50
51
52
# File 'lib/pagseguro/client.rb', line 50

def transactions
  @transactions ||= Transactions.new(self)
end

#url_for(source, path, params = {}) ⇒ Object



54
55
56
57
58
59
# File 'lib/pagseguro/client.rb', line 54

def url_for(source, path, params = {})
  url = URI(send("#{source}_url"))
  url.path = path
  url.query = params.to_query
  url.to_s
end