GithubHelp home page GithubHelp logo

emmanueloga / firering Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 13.0 349 KB

Eventmachine powered Campfire API

Home Page: http://www.rubydoc.info/github/EmmanuelOga/firering/master/frames

License: MIT License

Ruby 100.00%

firering's Introduction

firering

Campfire API interface powered by eventmachine, em-http-request and yajl-ruby.

Sample code

require 'firering'

print "Enter subdomain: "; subdomain = gets.chomp
print "Enter user: "     ; login     = gets.chomp
print "Enter password: " ; password  = gets.chomp

conn = Firering::Connection.new("http://#{subdomain}.campfirenow.com") do |c|
  c.login = login
  c.password = password
  c.max_retries = 10 # default to -1, which means perform connection retries on drop forever.
end

EM.run do
  conn.authenticate do |user|
    conn.rooms do |rooms|

      rooms.each do |room|
        if room.name == "Room Name"

          room.stream do |message|
            message.user { |user| puts "#{user}: #{message}" }
          end

        end
      end

    end
  end

  trap("INT") { EM.stop }
end

Specifying connection options:

An user agent can be specified. HTTP Options correspond to EM::HTTPRequest options:

conn = Firering::Connection.new("http://#{subdomain}.campfirenow.com") do |conn|
  conn.user_agent = "My Cool App 1.0"
  conn.http_options = {
    proxy: {
      host: url,
      port: port,
      authorization: [username, password]
    }
  }
end

campf-notif

The gem bundles an executable script for spawning libnotify powered notifications. To be able to use it, check your distro package repositories for the apropriate package containing the "notify-send" command line utility. In the case of archlinux, the package name is "libnotify".

The script needs the following environment variables in place:

CAMPFIRE_SUBDOMAIN CAMPFIRE_TOKEN

Once the variables are set, run the script as follows:

campf-notify room-name /path/to/an/icon.png

And watch the lovely notifications each time something is posted to a room.

Running the specs

When the specs are run a process is forked where a Rack application is run. This rack application serves all the fixtured responses that mimic the working of the real campfire app. The only caveat here is you may get a conflict if you are already running something on the port (8909). If this happens you'll need to open the specs/spec_helper.rb file and change the port used to run the fixtures server.

For more details take a look at spec/fixtures/load_server.rb file.

TODO

  • Better API documentation
  • Post files to a room
  • Retrieve recently uploaded files

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Contributors

See https://github.com/EmmanuelOga/firering/graphs/contributors

Copyright

Copyright (c) 2013 Emmanuel Oga. See LICENSE for details.

firering's People

Contributors

caius avatar elia avatar franckverrot avatar gdb avatar greggroth avatar icco avatar indirect avatar katzj avatar keith avatar semanticart avatar

Stargazers

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

Watchers

 avatar  avatar

firering's Issues

Twitter/campfire/something?

I'm getting this in my camper_van logs, which said to come here:

2012-10-22 21:16:33 7861 WARN CamperVan : WARNING: Could not set attribute 'tweet' to value '{:author_avatar_url=>"http://a0.twimg.com/profile_images/1554125521/engine-yard-twitter_normal.jpg", :author_username=>"eycloud", :id=>260489660684455936, :message=>"@denwwer hi,
try http://t.co/hYiNfJCt, let me know if you have any issues."}' on Firering::Message object. It is likely the Campfire API has changed. Please report this! (https://github.com/EmmanuelOga/firering/issues)

Robin

Please push latest changes on master to RubyGems

Hello,

The latest changes on master that bumped the version of yajl-ruby being used would be great to get up to rubygems. I'm trying to work with the CamperVan gem right now and firering's dependency on the old yajl-ruby is currently a showstopper for me.

Could we push the changes that are currently on master to a new version on rubygems? :)

Thanks much,
Andrew.

Undefined method [] for nil

Seems like on this line the data can come back as nil if the campfire server server has been deleted or your access has been revoked. Through camper_van I fixed this locally by just checking if data was nil before checking data[:rooms]

crash on tweet messages

I'm seeing crashes in firering when using camper_van. I'll try to dig into this when time allows, but just wanted to log this here.

2013-02-11_23:15:23.02081 2013-02-11 18:15:23 60825  WARN CamperVan : WARNING: Could not set attribute 'tweet' to value '{:author_avatar_url=>"http://a0.twimg.com/profile_images/3229180137/23b5b5ea2404a028bc4146d745a6520b_normal.jpeg", :author_username=>"IMDb_Reviews", :id=>300250249744756736, :message=>"There's a goat in the film who plays the mascot and he does a good job; but you wouldn't see a movie for a goat"}' on Firering::Message object. It is likely the Campfire API has changed. Please report this! (https://github.com/EmmanuelOga/firering/issues)
2013-02-11_23:15:23.02195 2013-02-11 18:15:23 60825  INFO CamperVan : closed connection from 127.0.0.1
2013-02-11_23:15:23.02208 2013-02-11 18:15:23 60825 ERROR CamperVan : http error . Trying again in 2 seconds...
2013-02-11_23:15:23.02226 /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/camper_van-0.0.6/lib/camper_van/utils.rb:15:in `stringify_keys': undefined method `keys' for #<String:0x007fd4029466b8> (NoMethodError)
2013-02-11_23:15:23.02230       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/camper_van-0.0.6/lib/camper_van/channel.rb:370:in `block in map_message_to_irc'
2013-02-11_23:15:23.02230       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/camper_van-0.0.6/lib/camper_van/channel.rb:390:in `user_for_message'
2013-02-11_23:15:23.02234       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/camper_van-0.0.6/lib/camper_van/channel.rb:260:in `map_message_to_irc'
2013-02-11_23:15:23.02235       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/camper_van-0.0.6/lib/camper_van/channel.rb:250:in `block in stream_campfire_to_channel'
2013-02-11_23:15:23.02235       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/firering-1.2.2/lib/firering/connection.rb:90:in `call'
2013-02-11_23:15:23.02235       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/firering-1.2.2/lib/firering/connection.rb:90:in `block in stream'
2013-02-11_23:15:23.02236       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/firering-1.2.2/lib/firering/connection.rb:103:in `call'
2013-02-11_23:15:23.02236       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/firering-1.2.2/lib/firering/connection.rb:103:in `<<'
2013-02-11_23:15:23.02236       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/firering-1.2.2/lib/firering/connection.rb:103:in `block in stream'
2013-02-11_23:15:23.02237       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/em-http-request-0.3.0/lib/em-http/client.rb:275:in `call'
2013-02-11_23:15:23.02238       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/em-http-request-0.3.0/lib/em-http/client.rb:275:in `on_decoded_body_data'
2013-02-11_23:15:23.02238       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/em-http-request-0.3.0/lib/em-http/client.rb:268:in `on_body_data'
2013-02-11_23:15:23.02238       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/em-http-request-0.3.0/lib/em-http/client.rb:582:in `process_chunk_body'
2013-02-11_23:15:23.02238       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/em-http-request-0.3.0/lib/em-http/client.rb:330:in `dispatch'
2013-02-11_23:15:23.02239       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/em-http-request-0.3.0/lib/em-http/client.rb:256:in `receive_data'
2013-02-11_23:15:23.02239       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
2013-02-11_23:15:23.02239       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
2013-02-11_23:15:23.02240       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/camper_van-0.0.6/lib/camper_van/server.rb:21:in `run'
2013-02-11_23:15:23.02241       from /Users/jd/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/camper_van-0.0.6/bin/camper_van:64:in `<top (required)>'
2013-02-11_23:15:23.02241       from /Users/jd/.rbenv/versions/1.9.3-p194/bin/camper_van:23:in `load'
2013-02-11_23:15:23.02241       from /Users/jd/.rbenv/versions/1.9.3-p194/bin/camper_van:23:in `<main>'

Missing Support for User-Agent

(37signals ops here...)

We've noticed a number of misbehaving Campfire clients. firering should identify itself like a good neighbor. Libraries that use firering should be able to identify themselves as well.

Tried to set starred="false" on a Firering::Message

2012-02-24 09:39:32 29407  INFO CamperVan : got connection from 127.0.0.1
2012-02-24 09:39:32 29407  INFO CamperVan : performing request to https://example.campfirenow.com/users/me.json
2012-02-24 09:39:33 29407  INFO CamperVan : performing request to https://example.campfirenow.com/users/me.json
2012-02-24 09:39:38 29407  INFO CamperVan : performing request to https://example.campfirenow.com/rooms.json
2012-02-24 09:39:39 29407  INFO CamperVan : performing request to https://example.campfirenow.com/room/423619.json
2012-02-24 09:39:39 29407  INFO CamperVan : performing request to https://example.campfirenow.com/room/423619/join.json
2012-02-24 09:39:40 29407  INFO CamperVan : performing streaming request to https://streaming.campfirenow.com/room/423619/live.json
2012-02-24 09:39:46 29407  INFO CamperVan : performing request to https://example.campfirenow.com/room/423619/speak.json
2012-02-24 09:39:49 29407  WARN CamperVan : WARNING: Tried to set starred= "false" on a Firering::Message instance but it didn't respond. Probably the API got updated, please report this! (https://github.com/EmmanuelOga/firering/issues)
2012-02-24 09:39:49 29407  INFO CamperVan : performing request to https://example.campfirenow.com/users/960484.json
2012-02-24 09:39:50 29407  INFO CamperVan : closed connection from 127.0.0.1
2012-02-24 09:39:50 29407 ERROR CamperVan : http error . Trying again in 2 seconds...
/Users/myusername/src/camper_van/lib/camper_van/channel.rb:266:in `block in map_message_to_irc': unexpected return (LocalJumpError)
        from /Users/myusername/src/camper_van/lib/camper_van/channel.rb:390:in `block in user_for_message'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/firering-1.1.1/lib/firering/instantiator.rb:28:in `call'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/firering-1.1.1/lib/firering/instantiator.rb:28:in `instantiate'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/firering-1.1.1/lib/firering/requests.rb:15:in `block in user'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/firering-1.1.1/lib/firering/connection.rb:68:in `call'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/firering-1.1.1/lib/firering/connection.rb:68:in `block in http'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/eventmachine-0.12.10/lib/em/deferrable.rb:134:in `call'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/eventmachine-0.12.10/lib/em/deferrable.rb:134:in `set_deferred_status'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/eventmachine-0.12.10/lib/em/deferrable.rb:173:in `succeed'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/em-http-request-0.3.0/lib/em-http/client.rb:307:in `unbind'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/eventmachine-0.12.10/lib/eventmachine.rb:1417:in `event_callback'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
        from /Users/myusername/src/camper_van/lib/camper_van/server.rb:21:in `run'
        from /Users/myusername/src/camper_van/bin/camper_van:57:in `<top (required)>'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/bin/camper_van:19:in `load'
        from /Users/myusername/.rvm/gems/ruby-1.9.3-p0@camper_van/bin/camper_van:19:in `<main>'

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.