Class: MediumApi::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/medium_api/client.rb

Overview

A main class to make http calls to medium.com

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
# File 'lib/medium_api/client.rb', line 17

def initialize(api_key:)
  @api_key = api_key

  self.class.headers("Authorization" => "Bearer #{api_key}")
end

Instance Attribute Details

#api_key ⇒ Object (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

Instance Method Details

#create_user_post(user_id, post_attributes) ⇒ Array<Hash>

Creates user post for provided user_id

Parameters:

  • user_id (String, Integer)
  • post_attributes (Hash)

Returns:

  • (Array<Hash>)

Raises:

See Also:



61
62
63
64
65
# File 'lib/medium_api/client.rb', line 61

def create_user_post(user_id, post_attributes)
  with_error_handling do
    self.class.post("/users/#{user_id}/posts", body: Utils.camelcase_keys(post_attributes))
  end
end

#me ⇒ Hash

Returns current user for specified api_key

Returns:

  • (Hash)

Raises:



26
27
28
29
30
# File 'lib/medium_api/client.rb', line 26

def me
  with_error_handling do
    self.class.get('/me')
  end
end

#publication_contributors(publication_id) ⇒ Array<Hash>

Return contributors for provided publication_id

Parameters:

  • publication_id (String, Integer)

Returns:

  • (Array<Hash>)

Raises:



47
48
49
50
51
# File 'lib/medium_api/client.rb', line 47

def publication_contributors(publication_id)
  with_error_handling do
    self.class.get("/publications/#{publication_id}/contributors")
  end
end

#user_publications(user_id) ⇒ Array<Hash>

Return publications for provided user_id

Parameters:

  • user_id (String, Integer)

Returns:

  • (Array<Hash>)

Raises:



37
38
39
40
41
# File 'lib/medium_api/client.rb', line 37

def user_publications(user_id)
  with_error_handling do
    self.class.get("/users/#{user_id}/publications")
  end
end