Class: Bootpay::Commerce::Api

Inherits:
CommerceResource show all
Defined in:
lib/bootpay_commerce.rb

Overview

Bootpay Commerce API 클라이언트

사용 예시:

commerce = Bootpay::Commerce::Api.new(
  client_key: 'your_client_key',
  secret_key: 'your_secret_key',
  mode: 'production'
)

# 액세스 토큰 발급
token_response = commerce.get_access_token

# Role 설정 (메서드 체이닝 지원)
commerce.as_manager

# 사용자 목록 조회
users = commerce.user.list(page: 1, limit: 10)

# 상품 생성 (이미지 포함)
product = commerce.product.create({ name: '상품명', price: 10000 }, ['/path/to/image.jpg'])

Constant Summary

Constants inherited from CommerceResource

CommerceResource::API_ENTRYPOINTS, CommerceResource::API_VERSION, CommerceResource::SDK_TYPE, CommerceResource::SDK_VERSION

Instance Attribute Summary collapse

Attributes inherited from CommerceResource

#client_key, #mode, #secret_key

Instance Method Summary collapse

Methods inherited from CommerceResource

#delete, #get, #get_role, #get_token, #post, #post_multipart, #post_with_basic_auth, #put, #set_configuration, #set_role, #set_token

Constructor Details

#initialize(client_key: nil, secret_key: nil, mode: 'production') ⇒ Api

Returns a new instance of Api.



49
50
51
52
53
54
55
# File 'lib/bootpay_commerce.rb', line 49

def initialize(client_key: nil, secret_key: nil, mode: 'production')
  super()
  if client_key && secret_key
    set_configuration(client_key: client_key, secret_key: secret_key, mode: mode)
  end
  init_modules
end

Instance Attribute Details

#cartObject (readonly)

Returns the value of attribute cart.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def cart
  @cart
end

#categoryObject (readonly)

Returns the value of attribute category.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def category
  @category
end

#couponObject (readonly)

Returns the value of attribute coupon.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def coupon
  @coupon
end

#invoiceObject (readonly)

Returns the value of attribute invoice.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def invoice
  @invoice
end

#orderObject (readonly)

Returns the value of attribute order.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def order
  @order
end

#order_cancelObject (readonly)

Returns the value of attribute order_cancel.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def order_cancel
  @order_cancel
end

#order_subscriptionObject (readonly)

Returns the value of attribute order_subscription.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def order_subscription
  @order_subscription
end

#order_subscription_adjustmentObject (readonly)

Returns the value of attribute order_subscription_adjustment.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def order_subscription_adjustment
  @order_subscription_adjustment
end

#order_subscription_billObject (readonly)

Returns the value of attribute order_subscription_bill.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def order_subscription_bill
  @order_subscription_bill
end

#order_subscription_requestObject (readonly)

Returns the value of attribute order_subscription_request.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def order_subscription_request
  @order_subscription_request
end

#pointObject (readonly)

Returns the value of attribute point.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def point
  @point
end

#productObject (readonly)

Returns the value of attribute product.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def product
  @product
end

#storeObject (readonly)

Returns the value of attribute store.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def store
  @store
end

#userObject (readonly)

Returns the value of attribute user.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def user
  @user
end

#user_groupObject (readonly)

Returns the value of attribute user_group.



44
45
46
# File 'lib/bootpay_commerce.rb', line 44

def user_group
  @user_group
end

Instance Method Details

#as_managerObject

매니저 role로 설정



101
102
103
# File 'lib/bootpay_commerce.rb', line 101

def as_manager
  with_role('manager')
end

#as_partnerObject

파트너 role로 설정



106
107
108
# File 'lib/bootpay_commerce.rb', line 106

def as_partner
  with_role('partner')
end

#as_supervisorObject

슈퍼바이저 role로 설정



116
117
118
# File 'lib/bootpay_commerce.rb', line 116

def as_supervisor
  with_role('supervisor')
end

#as_userObject

일반 사용자 role로 설정



96
97
98
# File 'lib/bootpay_commerce.rb', line 96

def as_user
  with_role('user')
end

#as_vendorObject

벤더 role로 설정



111
112
113
# File 'lib/bootpay_commerce.rb', line 111

def as_vendor
  with_role('vendor')
end

#clear_roleObject

role을 기본값(user)으로 초기화



126
127
128
129
# File 'lib/bootpay_commerce.rb', line 126

def clear_role
  set_role('user')
  self
end

#current_roleObject

현재 role 반환



121
122
123
# File 'lib/bootpay_commerce.rb', line 121

def current_role
  get_role
end

#current_tokenObject

현재 설정된 토큰 반환



79
80
81
# File 'lib/bootpay_commerce.rb', line 79

def current_token
  get_token
end

#get_access_tokenObject

액세스 토큰 발급client_key/secret_key로 Basic Auth 인증



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bootpay_commerce.rb', line 59

def get_access_token
  response = post_with_basic_auth('request/token', {
    client_key: @client_key,
    secret_key: @secret_key
  })

  if response.is_a?(Hash) && response[:access_token]
    set_token(response[:access_token])
  end

  response
end

#has_token?Boolean

토큰이 설정되어 있는지 확인

Returns:

  • (Boolean)


84
85
86
87
# File 'lib/bootpay_commerce.rb', line 84

def has_token?
  token = get_token
  !token.nil? && !token.empty?
end

#with_role(role) ⇒ Object

Role 설정 (메서드 체이닝)



90
91
92
93
# File 'lib/bootpay_commerce.rb', line 90

def with_role(role)
  set_role(role)
  self
end

#with_tokenObject

토큰을 발급받아 설정 (메서드 체이닝)



73
74
75
76
# File 'lib/bootpay_commerce.rb', line 73

def with_token
  get_access_token
  self
end