Class: ScrapboxClient::Client

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

Constant Summary collapse

BASE_URI_V1 =
"https://scrapbox.io"
URI_RESOURCE_MAP =
{
  page_list: "/api/pages/%{project_name}?skip=%{skip}&limit=%{limit}",
  page: "/api/pages/%{project_name}/%{page_title}",
  page_body: "/api/pages/%{project_name}/%{page_title}/text",
  page_image: "/api/pages/%{project_name}/%{page_title}/icon",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_name:) ⇒ Client

Returns a new instance of Client.



18
19
20
# File 'lib/scrapbox_client.rb', line 18

def initialize(project_name:)
  @project_name = project_name
end

Instance Attribute Details

#project_nameObject (readonly)

Returns the value of attribute project_name.



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

def project_name
  @project_name
end

Instance Method Details

#fetch_page(page_title:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/scrapbox_client.rb', line 33

def fetch_page(page_title:)
  return unless page_title
  params = {
    project_name: project_name,
    page_title: page_title,
  }
  res = request_api(resource: URI_RESOURCE_MAP[:page], params: params)

  return res
end

#fetch_page_body(page_title:) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/scrapbox_client.rb', line 44

def fetch_page_body(page_title:)
  return unless page_title
  params = {
    project_name: project_name,
    page_title: page_title,
  }
  res = request_api(resource: URI_RESOURCE_MAP[:page_body], params: params)

  return res
end

#fetch_page_image(page_title:) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/scrapbox_client.rb', line 55

def fetch_page_image(page_title:)
  return unless page_title
  params = {
    project_name: project_name,
    page_title: page_title,
  }
  res = request_api(resource: URI_RESOURCE_MAP[:page_image], params: params)

  return res
end

#fetch_page_list(skip: skip = 0, limit: limit = 100) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/scrapbox_client.rb', line 22

def fetch_page_list(skip: skip = 0, limit: limit = 100)
  params = {
    project_name: project_name,
    skip: skip,
    limit: limit,
  }
  res = request_api(resource: URI_RESOURCE_MAP[:page_list], params: params)

  return res
end