Giter Club home page Giter Club logo

flowdock-api's Introduction

Flowdock

Ruby gem for using the Flowdock Push API. See the Push API documentation for details.

Build Status

Build Status

The Flowdock gem is tested on Ruby 2.1 and JRuby.

Dependencies

  • HTTParty
  • MultiJson

Installing

gem install flowdock

If you're using JRuby, you'll also need to install the jruby-openssl gem.

Usage

To post content to a flow's chat or team inbox using Flowdock::Flow, you need to use the target flow's API token or a source's flow_token.

Alternatively, you can use your personal API token and the Flowdock::Client.

Personal and flow's tokens can be found on the tokens page.

REST API

To create an API client, you need your personal API token, an OAuth token or a source's flow_token.

Note that a flow_token will only allow you to post thread messages to the flow that the source belongs to.

require 'rubygems'
require 'flowdock'

# Create a client that uses your personal API token to authenticate
api_token_client = Flowdock::Client.new(api_token: '__MY_PERSONAL_API_TOKEN__')

# Create a client that uses a source's flow_token to authenticate. Can only use post_to_thread
flow_token_client = Flowdock::Client.new(flow_token: '__FLOW_TOKEN__')

Posting to Chat

To send a chat message or comment, you can use client.chat_message:

flow_id = 'acdcabbacd0123456789'

# Send a simple chat message
api_token_client.chat_message(flow: flow_id, content: "I'm sending a message!", tags: ['foo', 'bar'])

# Send a comment to message 1234
api_token_client.chat_message(flow: flow_id, content: "Now I'm commenting!", message: 1234)

Both methods return the created message as a hash.

Post a threaded messages

You can post activity and discussion events to a threaded conversation in Flowdock.

flow_token_client.post_to_thread(
    event: "activity",
    author: {
        name: "anttipitkanen",
        avatar: "https://avatars.githubusercontent.com/u/946511?v=2",
    },
    title: "activity title",
    external_thread_id: "your-id-here",
    thread: {
        title: "this is required if you provide a thread field at all",
        body: "<p>some html content</p>",
        external_url: "https://example.com/issue/123",
        status: {
            color: "green",
            value: "open"
        }
    }
)

Arbitary API access

You can use the client to access the Flowdock API in other ways, too. See the REST API documentation for all the resources.

# Fetch all my flows
flows = client.get('/flows')

# Update a flow's name
client.put('/flows/acme/my_flow', name: 'Your flow')

# Delete a message
client.delete('/flows/acme/my_flow/messages/12345')

# Create an invitation
client.post('/flows/acme/my_flow/invitations', email: '[email protected]', message: "I'm inviting you to our flow using api.")

Push API

Note: the Push API is in the process of being deprecated. Creating a source along with a flow_token is recommended instead.

To use the Push API, you need the flow's API token:

Posting to the chat

require 'rubygems'
require 'flowdock'

# create a new Flow object with target flow's API token and external user name (enough for posting to the chat)
flow = Flowdock::Flow.new(:api_token => "__FLOW_API_TOKEN__", :external_user_name => "John")

# send message to Chat
flow.push_to_chat(:content => "Hello!", :tags => ["cool", "stuff"])

Posting to the team inbox

# create a new Flow object with the target flow's API token and sender information
flow = Flowdock::Flow.new(:api_token => "__FLOW_API_TOKEN__",
  :source => "myapp", :from => {:name => "John Doe", :address => "[email protected]"})

# send message to Team Inbox
flow.push_to_team_inbox(:subject => "Greetings from the Flowdock API gem!",
  :content => "<h2>It works!</h2><p>Now you can start developing your awesome application for Flowdock.</p>",
  :tags => ["cool", "stuff"], :link => "http://www.flowdock.com/")

Posting to multiple flows

require 'rubygems'
require 'flowdock'

# create a new Flow object with the API tokens of the target flows
flow = Flowdock::Flow.new(:api_token => ["__FLOW_API_TOKEN__", "__ANOTHER_FLOW_API_TOKEN__"], ... )

# see the above examples of posting to the chat or team inbox

API methods

  • Flowdock::Flow methods

    push_to_team_inbox - Send message to the team inbox. See API documentation for details.

    push_to_chat - Send message to the chat. See API documentation for details.

    send_message(params) - Deprecated. Please use push_to_team_inbox instead.

  • Flowdock::Client methods

    chat_message - Send message to chat.

    post_to_thread - Post messages to a team inbox thread.

    post, get, put, delete - Send arbitary api calls. First parameter is the path, second is data. See REST API documentation.

Deployment notifications

There are separate gems for deployment notifications:

Changelog

  • 0.7.0 - Added post_to_thread
  • 0.5.0 - Added Flowdock::Client that authenticates using user credentials and can be used to interact with the API. Better threads support for both Flow and Client so that comments can be made.

Copyright

Copyright (c) 2012 Flowdock Ltd. See LICENSE for further details.

flowdock-api's People

Contributors

andreaso avatar beanieboi avatar elskwid avatar jlehikoi avatar lautis avatar martinsvalin avatar muffinista avatar mumakil avatar pdaugavietis avatar phlipper avatar sakari avatar skoschnicke avatar srmelody-rally avatar vsaarinen avatar zmalone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flowdock-api's Issues

I would like to be able to announce to multiple flows

We would like to announce deploys to every room (or to an enumerated list of rooms). This is pretty difficult with the current version. I see two obvious options:

  1. add a Ruby API that looks like a multi-flow announcement, but really just makes multiple HTTP requests
  2. add true multi-flow announcements to the Flowdock HTTP API (say, with a comma-separated list)

I'm happy to help with the former or with the Ruby part of the latter.

Httparty can't install on 1.8.7: breaks Travis build

All the builds are apparently error-ing because of HTTParty failing to install in 1.8.7. Now, 1.8.7 saw end of life in July iirc, I don't know why you're still building against it.
In case you do need to do it, you need to either lockdown httparty to a version that ran in 1.8.7 or switch to a different http library (such as 1.8.7's Net::HTTP for example).

Able to set timeout?

HI
I am using this in production app and sometimes it slows down the app, can there be option for HTTPParty via Flow clas to set timeout?

thanks

Git-aware notification does not work if branch not defined

I've purposefully not set :branch in my Capfile, to be able to deploy the currently checked out branch. This causes notifications to fail, however, wth

    triggering after callbacks for `deploy'
  * 2013-10-15 10:47:00 executing `flowdock:notify_deploy_finished'
    triggering before callbacks for `flowdock:notify_deploy_finished'
  * 2013-10-15 10:47:00 executing `flowdock:set_flowdock_api'
Flowdock: error in sending notification to your flow: undefined local variable or method `branch' for #<Capistrano::Configuration::Namespaces::Namespace:0x007fcff24d2168>
  * 2013-10-15 10:47:00 executing `flowdock:save_deployed_branch'
  * executing "echo 'HEAD' > /path/to/myapp/current/BRANCH"

I think the process should be smart enough to git rev-parse --abbrev-ref HEAD if the branch has not been given.

cap deploy:symlink doesn't work now

Yeah, after last issue ( #4 ) this was quite obvious :)

So i'm not sure where it should be handled normally. But in generally I would want that flowdock would never create errors in my capistrano excecutements. Especially it should never stop my deploying scripts. If I break my production server, i want to be able to use the commants as excected, then I don't really care if flow gets notified or not, I'm in a hurry...

It should just pass and log some errors etc. In https://github.com/flowdock/flowdock-api/blob/master/lib/flowdock/capistrano.rb#L36 something like

unless defined?(current_branch)
   your code
else
   puts "Flowdock could not be informed, no branch set, debug or contact support"
end

Some trace:

    command finished in 738ms
    triggering after callbacks for `deploy:symlink'
  * executing `flowdock:notify_deploy_finished'
    triggering before callbacks for `flowdock:notify_deploy_finished'
  * executing `flowdock:set_flowdock_api'
    triggering before callbacks for `flowdock:set_flowdock_api'
/home/ohu/.rvm/gems/ree-1.8.7-2011.03/gems/capistrano-2.9.0/lib/capistrano/configuration/namespaces.rb:188:in `method_missing': undefined local variable or method `current_branch' for #<Capistrano::Configuration::Namespaces::Namespace:0x24fbe68> (NameError)

Support proxy server

Hi - trying to get this to support proxy servers, as it's a requirement for my implementation. I'm not seeing an easy way to pass thru options to HTTParty, but i think on HTTParty side should be easy to add the necessary options for proxy support if needed.

I'm wondering if maybe a bit of refactor around HOW options are passed back to HTTParty - maybe a hash instead of just a bunch of KV pairs? Thoughts? Help? :)

No Changelog

It's very convenient to have a changelog when updating gems just to have an idea what could break. Thanks.

Gem version

Hey,

Last version of the gem (0.3.1) is 11 months old, do you plan to release a new version anytime soon ?

Thanks

"GET /users" doesn't get updated

GET /flows/:organization/:flow/users

contains users who where kicked from the organization.

For example: The user "MasterX" was kicked about 3 months ago.

GET /organizations/:organization/users

does not show him but the first call does.

cap deploy:restart doesnt work after requiring flowdock

cap deploy:restart


  * executing `deploy:restart'
    triggering before callbacks for `deploy:restart'
  * executing "touch ..cap/current/tmp/restart.txt"
....
    triggering after callbacks for `deploy:restart'
  * executing `flowdock:notify_deploy_finished'
    triggering before callbacks for `flowdock:notify_deploy_finished'
  * executing `flowdock:set_flowdock_api'
    triggering before callbacks for `flowdock:set_flowdock_api'

triggering before callbacks for `flowdock:set_flowdock_api'
...lobal/gems/capistrano-2.9.0/lib/capistrano/configuration/namespaces.rb:188:in `method_missing': undefined local variable or method `current_branch' for #<Capistrano::Configuration::Namespaces::Namespace:0x3c7ee00> (NameError)

Maybe at: https://github.com/flowdock/flowdock-api/blob/master/lib/flowdock/capistrano.rb#L62

I would use somthing related to "deploy:symlink"

Anyway, I'm not sure if server restart should be informed by default. But at least calling plain "cap deploy:restart" should work as before.

Otherwise, it works great. With usual deploy notifies are good.

Problem when capistrano variable 'stage' is undefined

I think there is a problem in the capistrano file, line 19 (https://github.com/flowdock/flowdock-api/blob/master/lib/flowdock/capistrano.rb#L19 ):

set :rails_env, (!stage.nil?) ? stage : ENV['RAILS_ENV']

Because capistrano provides "variables" via method_missing, calling nil? on an undefined capistrano variable results in

 `method_missing': undefined local variable or method `stage'

see http://groups.google.com/group/capistrano/browse_thread/thread/57733d9ce4c43ad2

A solution would be using variables.include?(:stage) instead of stage.nil?

Don't access repo directly

For automated environments (like my continuous deployment Jenkins setup) I don't have a git repo, so going through the repo directly to get list of changes between deploys is error-prone.
Now, as pointed before in capistrano/capistrano#757 I set previous_revision and current_revision variables back in Capistrano 3.
I might be able to work on a fix for this particular scenario on Capistrano 2, but I'm not really sure whether I'll have the time to do it.
In Capistrano 3, we should prefer to go through the aforementioned variables instead of the repo instance, as it might not exist at all. All the information should be retrieved from the remote and the current state of the local checkout on the deployment server as opposed to the local one.
Comments welcome.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.