PostWill

Posting to the most popular social media from Ruby.

               

Installation

Add this line to your application's Gemfile:

gem 'postwill'

And then execute:

$ bundle

Single provider

postwill = Postwill::Client.new(
                   twitter: {
                     access_token: 'access_token',
                     access_token_secret: 'access_token_secret'
                   }
                 )

postwill.to(:twitter, text: 'text', image: 'image')

Success:

{
  twitter: {
    status: :ok,
    response: {} # Hash of response data depends on provider
  }
}

Failure:

{
  twitter: {
    status: :error,
    response: '' # String error message
  }
}

Application credentials (for providers which need them)

config/initializers/postwill.rb

Postwill::Settings.configure do |config|
  config.providers.twitter = {
    consumer_key: 'your_consumer_key',
    consumer_secret: 'your_consumer_secret'
  }
end

Multiple providers

postwill = Postwill::Client.new(
                 twitter: {
                   access_token: 'access_token',
                   access_token_secret: 'access_token_secret'
                 },
                 facebook: {
                   access_token: 'access_token'
                 }
               )

postwill.to(%i[twitter facebook], text: 'text', image: 'image')

Result:

{
  twitter: {
    status: :ok,
    response: {} # Response data
  },
  facebook: {
    status: :ok,
    response: {} # Response data
  }
}

Available providers

Twitter

Based on: Twitter

postwill = Postwill::Client.new(
                   twitter: {
                     access_token: 'access_token',
                     access_token_secret: 'access_token_secret'
                   }
                 )

postwill.to(:twitter, text: 'text', image: 'image')

Success:

{
  twitter: {
    status: :ok,
    response: {} # Response data
  }
}

Failure:

{
  twitter: {
    status: :error,
    response: '' # String error message
  }
}

Settings:

Postwill::Settings.configure do |config|
  config.providers.twitter = {
    consumer_key: 'your_consumer_key',
    consumer_secret: 'your_consumer_secret'
  }
end

Facebook

Based on: Koala

postwill = Postwill::Client.new(
                   facebook: {
                     access_token: 'access_token'
                   }
                 )

postwill.to(:facebook, text: 'text', image: 'image')

Success:

{
  facebook: {
    status: :ok,
    response: {} # Response data
  }
}

Failure:

{
  facebook: {
    status: :error,
    response: '' # String error message
  }
}

Pinterest

Based on: PinterestApi

postwill = Postwill::Client.new(
                   pinterest: {
                     access_token: 'access_token'
                   }
                 )

# Reqired: [board_id image image_url]
# Optional: [text link]
postwill.to(:pinterest, text: 'text', image: 'image', board_id: 'board_id', link: 'link')
# OR
postwill.to(:pinterest, text: 'text', image_url: 'image_url', board_id: 'board_id', link: 'link')

Success:

{
  pinterest: {
    status: :ok,
    response: {
      'data' => {
        'url' => 'PIN_LINK',
        'note' => 'text',
        'link' => 'LINK',
        'id' => 'PIN_ID'
      }
    }
  }
}

Failure:

{
  pinterest: {
    status: :error,
    response: '' # String error message
  }
}

Tumblr

Based on: TumblrClient

postwill = Postwill::Client.new(
                   tumblr: {
                     access_token: 'access_token',
                     access_token_secret: 'access_token_secret'
                   }
                 )

# Reqired: [user_nickname text image title]

postwill.to(:tumblr, text: 'text', image: 'image', user: 'user_nickname')
# or
postwill.to(:tumblr, text: 'text', title: 'title', user: 'user_nickname')

Success:

{
  tumblr: {
    status: :ok,
    response: {
      {
        'id' => 'POST_ID'
      }
    }
  }
}

Failure:

{
  tumblr: {
    status: :error,
    response: '' # String error message
  }
}

Settings:

Postwill::Settings.configure do |config|
  config.providers.tumblr = {
    consumer_key: 'consumer_key',
    consumer_secret: 'consumer_secret'
  }
end

Instagram

Based on: InstagramUpload

postwill = Postwill::Client.new(
                   instagram: {
                     username: 'username',
                     password: 'password'
                   }
                 )

postwill.to(:instagram, text: 'text', image: 'image')

Success:

{
  instagram: {
    status: :ok,
    response: {} # Response data
  }
}

Failure:

{
  instagram: {
    status: :error,
    response: '' # String error message
  }
}