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,
  }
)

Parameters:

  • base_url (String) (defaults to: nil)

    The base URL for requests (optional). Defaults to ‘manager.line.biz’ if none is provided. You can override this for testing or to use a mock server.

  • channel_id (String)

    The channel ID for Basic authentication.

  • channel_secret (String)

    The channel secret for Basic authentication.

  • http_options (Hash) (defaults to: {})

    HTTP options (same as Net::HTTP options). See: docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.



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.

Parameters:

  • grant_type (String)

    authorization_code

  • code (String)

    Authorization code received from the LINE Platform.

  • redirect_uri (String)

    Specify the redirect_uri specified in the URL for authentication and authorization.

  • code_verifier (String, nil) (defaults to: nil)

    Specify when using PKCE (Proof Key for Code Exchange) defined in the OAuth 2.0 extension specification as a countermeasure against authorization code interception attacks.

  • client_id (String, nil) (defaults to: nil)

    Instead of using Authorization header, you can use this parameter to specify the channel ID of the module channel. You can find the channel ID of the module channel in the LINE Developers Console.

  • client_secret (String, nil) (defaults to: nil)

    Instead of using Authorization header, you can use this parameter to specify the channel secret of the module channel. You can find the channel secret of the module channel in the LINE Developers Console.

  • region (String, nil) (defaults to: nil)

    If you specified a value for region in the URL for authentication and authorization, specify the same value.

  • basic_search_id (String, nil) (defaults to: nil)

    If you specified a value for basic_search_id in the URL for authentication and authorization, specify the same value.

  • scope (String, nil) (defaults to: nil)

    If you specified a value for scope in the URL for authentication and authorization, specify the same value.

  • brand_type (String, nil) (defaults to: nil)

    If you specified a value for brand_type in the URL for authentication and authorization, specify the same value.

Returns:

See Also:



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.

Parameters:

  • grant_type (String)

    authorization_code

  • code (String)

    Authorization code received from the LINE Platform.

  • redirect_uri (String)

    Specify the redirect_uri specified in the URL for authentication and authorization.

  • code_verifier (String, nil) (defaults to: nil)

    Specify when using PKCE (Proof Key for Code Exchange) defined in the OAuth 2.0 extension specification as a countermeasure against authorization code interception attacks.

  • client_id (String, nil) (defaults to: nil)

    Instead of using Authorization header, you can use this parameter to specify the channel ID of the module channel. You can find the channel ID of the module channel in the LINE Developers Console.

  • client_secret (String, nil) (defaults to: nil)

    Instead of using Authorization header, you can use this parameter to specify the channel secret of the module channel. You can find the channel secret of the module channel in the LINE Developers Console.

  • region (String, nil) (defaults to: nil)

    If you specified a value for region in the URL for authentication and authorization, specify the same value.

  • basic_search_id (String, nil) (defaults to: nil)

    If you specified a value for basic_search_id in the URL for authentication and authorization, specify the same value.

  • scope (String, nil) (defaults to: nil)

    If you specified a value for scope in the URL for authentication and authorization, specify the same value.

  • brand_type (String, nil) (defaults to: nil)

    If you specified a value for brand_type in the URL for authentication and authorization, specify the same value.

Returns:

  • (Array(Line::Bot::V2::ModuleAttach::AttachModuleResponse, Integer, Hash{String => String}))

    when HTTP status code is 200

  • (Array((String|nil), Integer, Hash{String => String}))

    when other HTTP status code is returned. String is HTTP response body itself.

See Also:



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