Class: ReamazeAPI::Article

Inherits:
Resource show all
Defined in:
lib/reamaze_api/article.rb

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from ReamazeAPI::Resource

Instance Method Details

#all(params = {}) ⇒ Object

Retrieves KB articles.

Parameters:

  • params (defaults to: {})

    Hash of parameters to pass to the API

  • API

    Routes GET /articles GET /topics/slug/articles

  • See

Returns:

  • a Hash.



15
16
17
18
19
20
# File 'lib/reamaze_api/article.rb', line 15

def all(params = {})
  params = Utils.symbolize_hash(params)
  url    = articles_path(params.delete(:topic))

  paginate url, :articles, params
end

#articles_path(topic_slug = nil) ⇒ Object (private)

Private: Articles API path. If a topic slug is supplied the returned path is prefixed with “/topic/#topic”.

Parameters:

  • topic_slug (defaults to: nil)

    The topic slug

Returns:

  • a String.



79
80
81
82
83
84
85
# File 'lib/reamaze_api/article.rb', line 79

def articles_path(topic_slug = nil)
  if topic_slug
    "/topics/#{topic_slug}/articles"
  else
    "/articles"
  end
end

#create(params) ⇒ Object

Create a new KB article.

Parameters:

  • params

    Hash of parameters to pass to the API

  • API

    Routes POST /articles (no topic) POST /topics/slug/articles

  • See

Returns:

  • a Hash.



49
50
51
52
53
# File 'lib/reamaze_api/article.rb', line 49

def create(params)
  params = Utils.symbolize_hash(params)

  post articles_path(params.delete(:topic)), params
end

#find(slug) ⇒ Object

Retrieves a specific KB article.

Parameters:

Returns:

  • a Hash.



33
34
35
# File 'lib/reamaze_api/article.rb', line 33

def find(slug)
  get "/articles/#{slug}"
end

#update(slug, params) ⇒ Object

Update an existing KB article.

Parameters:

Returns:

  • a Hash.



67
68
69
# File 'lib/reamaze_api/article.rb', line 67

def update(slug, params)
  put "/articles/#{slug}", params
end