Class: Medium::Posts

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Posts

Returns a new instance of Posts.



3
4
5
# File 'lib/medium/posts.rb', line 3

def initialize(client)
  @client = client
end

Instance Method Details

#create(opts) ⇒ Hash

Creates a post on the authenticated user’s profile.

Parameters:

  • opts (Hash)

    A hash of options to use when creating a post. The opts hash requires the keys: :title, :content_format, and :content. The following keys are optional: :tags, :canonical_url, :publish_status, and :license

Returns:

  • (Hash)

    The response is a Post object within a data envelope. Example response:

    HTTP/1.1 201 OK
    Content-Type: application/json; charset=utf-8
    {
      "data": {
        "id": "e6f36a",
        "title": "Liverpool FC",
        "authorId": "5303d74c64f66366f00cb9b2a94f3251bf5",
        "tags": ["football", "sport", "Liverpool"],
        "url": "https://medium.com/@majelbstoat/liverpool-fc-e6f36a",
        "canonicalUrl": "http://jamietalbot.com/posts/liverpool-fc",
        "publishStatus": "public",
        "publishedAt": 1442286338435,
        "license": "all-rights-reserved",
        "licenseUrl": "https://medium.com/policy/9db0094a1e0f"
      }
    }
    


33
34
35
36
# File 'lib/medium/posts.rb', line 33

def create(opts)
  @client.post "users/#{@client.users.me['data']['id']}/posts",
               build_request_with(opts)
end