Class: Pumi::Wikipedia::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_client: default_http_client) ⇒ Client

Returns a new instance of Client.



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

def initialize(http_client: default_http_client)
  @http_client = http_client
end

Instance Attribute Details

#http_clientObject (readonly)

Returns the value of attribute http_client.



6
7
8
# File 'lib/pumi/wikipedia/client.rb', line 6

def http_client
  @http_client
end

Instance Method Details

#create_page(params) ⇒ Object



12
13
14
# File 'lib/pumi/wikipedia/client.rb', line 12

def create_page(params)
  execute_request(:post, build_url(resource: :page), params)
end

#get_page(title:) ⇒ Object



35
36
37
# File 'lib/pumi/wikipedia/client.rb', line 35

def get_page(title:)
  execute_request(:get, build_url(resource: "page/#{title}"))
end

#page_exists?(title:) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/pumi/wikipedia/client.rb', line 39

def page_exists?(title:)
  response = get_page(title:)
  response.success?
end

#submit_for_review(title:, **params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pumi/wikipedia/client.rb', line 22

def submit_for_review(title:, **params)
  page = get_page(title:)
  execute_request(
    :put,
    build_url(resource: "page/#{title}"),
    latest: page.fetch(:latest),
    source: page.fetch(:source).prepend("{{subst:submit}}\n"),
    title:,
    comment: "Submit #{title} for review",
    **params
  )
end

#update_page(title:, **params) ⇒ Object



16
17
18
19
20
# File 'lib/pumi/wikipedia/client.rb', line 16

def update_page(title:, **params)
  page = get_page(title:)
  latest = page.fetch(:latest)
  execute_request(:put, build_url(resource: "page/#{title}"), latest:, **params)
end