Class: Line::Bot::V2::ModuleAttach::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/line/bot/v2/module_attach/api/line_module_attach_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url: nil, channel_id:, channel_secret:, http_options: {}) ⇒ ApiClient

Initializes a new Line::Bot::V2::ModuleAttach::ApiClient instance.

Examples:

@client ||= Line::Bot::V2::ModuleAttach::ApiClient.new(
  channel_id: "YOUR_CHANNEL_ID",
  channel_secret: "YOUR_CHANNEL_SECRET",
  http_options: {
    open_timeout: 5,
    read_timeout: 5,
  }
)


40
41
42
43
44
45
46
47
48
# File 'lib/line/bot/v2/module_attach/api/line_module_attach_client.rb', line 40

def initialize(base_url: nil, channel_id:, channel_secret:, http_options: {})
  @http_client = HttpClient.new(
    base_url: base_url || 'https://manager.line.biz',
    http_headers: {
      Authorization: 'Basic ' + Base64.encode64("#{channel_id}:#{channel_secret}")
    },
    http_options: http_options
  )
end

Instance Method Details

#attach_module(grant_type:, code:, redirect_uri:, code_verifier: nil, client_id: nil, client_secret: nil, region: nil, basic_search_id: nil, scope: nil, brand_type: nil) ⇒ Line::Bot::V2::ModuleAttach::AttachModuleResponse, ...

Attach by operation of the module channel provider This requests to POST https://manager.line.biz/module/auth/v1/token When you want to get HTTP status code or response headers, use #attach_module_with_http_info instead of this.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/line/bot/v2/module_attach/api/line_module_attach_client.rb', line 129

def attach_module(
  grant_type:,
  code:,
  redirect_uri:,
  code_verifier: nil,
  client_id: nil,
  client_secret: nil,
  region: nil,
  basic_search_id: nil,
  scope: nil,
  brand_type: nil
)
  response_body, _status_code, _headers = attach_module_with_http_info(
    grant_type: grant_type,
    code: code,
    redirect_uri: redirect_uri,
    code_verifier: code_verifier,
    client_id: client_id,
    client_secret: client_secret,
    region: region,
    basic_search_id: basic_search_id,
    scope: scope,
    brand_type: brand_type
  )

  response_body
end

#attach_module_with_http_info(grant_type:, code:, redirect_uri:, code_verifier: nil, client_id: nil, client_secret: nil, region: nil, basic_search_id: nil, scope: nil, brand_type: nil) ⇒ Array(Line::Bot::V2::ModuleAttach::AttachModuleResponse, Integer, Hash{String => String}), Array((String|nil), Integer, Hash{String => String})

Attach by operation of the module channel provider This requests to POST https://manager.line.biz/module/auth/v1/token This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/line/bot/v2/module_attach/api/line_module_attach_client.rb', line 67

def attach_module_with_http_info( # steep:ignore MethodBodyTypeMismatch 
  grant_type:, 
  code:, 
  redirect_uri:, 
  code_verifier: nil, 
  client_id: nil, 
  client_secret: nil, 
  region: nil, 
  basic_search_id: nil, 
  scope: nil, 
  brand_type: nil
)
  path = "/module/auth/v1/token"

  form_params = {
    "grant_type": grant_type,
    "code": code,
    "redirect_uri": redirect_uri,
    "code_verifier": code_verifier,
    "client_id": client_id,
    "client_secret": client_secret,
    "region": region,
    "basic_search_id": basic_search_id,
    "scope": scope,
    "brand_type": brand_type
  }.compact

  response = @http_client.post_form(
    path: path,
    form_params: form_params,
  )

  case response.code.to_i
  when 200
    json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
    json.transform_keys! do |key|
      Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
    end
    response_body = Line::Bot::V2::ModuleAttach::AttachModuleResponse.create(json) # steep:ignore InsufficientKeywordArguments
    [response_body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end