Code Monkey home page Code Monkey logo

podio-rb's Introduction

No Maintenance Intended

Podio

This is the official Ruby client for accessing the Podio API. Besides handling setup and authentication it also provides idiomatic Ruby methods for accessing most of the APIs operations. This client library is designed to be minimal and easily integrable into your projects.

Install

Podio is packaged as a gem:

$ gem install podio

Configuration

The main way of using the Podio library is via a singleton client, which you set up like this:

Podio.setup(:api_key => 'YOUR_API_KEY', :api_secret => 'YOUR_API_SECRET')

This initializes a Podio::Client object and assigns it to a thread-local, which is used by all methods in this library.

Authentication

After the configuration you need to authenticate against the API. The client supports two ways of authentication:

Web Server Flow

The default OAuth flow to be used when you authenticate Podio users from your web application. See the sinatra.rb in the examples folder.

# Redirect the user to the authorize url
Podio.client.authorize_url(:redirect_uri => redirect_uri)

# In the callback you get the authorization_code
# wich you use to get the access token
Podio.client.authenticate_with_auth_code(params[:code], redirect_uri)

Username and Password Flow

If you're writing a batch job or are just playing around with the API, this is the easiest to get started. Do not use this for authenticating users other than yourself, the web server flow is meant for that.

Podio.client.authenticate_with_credentials('USERNAME', 'PASSWORD')

Basic Usage

After you configured the Podio.client singleton you can use all of the wrapper functions to do API requests. The functions are organized into models corresponding to the official API documentation, although most API areas have multiple models associated. The method follow a common naming pattern that should be familiar to ActiveRecord users. For example:

# Getting an item
Podio::Item.find(42)

# Posting a status message on space with id 23
Podio::Status.create(23, {:value => 'This is the text of the status message'})

If there is a method missing or you want to do something special, you can use the Faraday connection directly. This allows you to do arbitrary HTTP requests to the Podio API with authentication, JSON parsing and error handling already taken care of. The same examples would look like this:

# Getting an item
response = Podio.connection.get('/item/42')
response.body

# Posting a status message on space with id 23
response = Podio.connection.post do |req|
  req.url '/status/space/23/'
  req.body = {:value => 'This is the text of the status message'}
end
response.body

All the wrapped methods either return a single model instance, an array of instances, or a simple Struct in case of pagination:

# Find all items in an app (paginated)
items = Podio::Item.find_all(app_id, :limit => 20)

# get count of returned items in this call
items.count

# get the returned items in an array
items.all

# get count of all items in this app
items.total_count

Active Podio

The Podio API is based on REST requests passing JSON back and forth, but we have tried to make the use of this client an experience more similar to using ActiveRecord from Rails. That means that all find methods return model instances with attributes cast to the expected type (string, integer, boolean, datetime, etc.). Also, models can be instantiated using a params hash, just like with ActiveRecord models.

While the models can be used directly from this gem, we encourage everyone using Podio in a Rails project to add models that extend the standard models:

class Item < Podio::Item # Inherits from the base model in the Podio gem

  # Your custom methods, e.g.:
  def application
    @app_instance ||= Application.find(self.app_id)
  end
end

Error Handling

All unsuccessful responses returned by the API (everything that has a 4xx or 5xx HTTP status code) will throw exceptions. All exceptions inherit from Podio::PodioError and have three additional properties which give you more information about the error:

begin
  Podio::Space.create({:name => 'New Space', :org_id => 42})
rescue Podio::BadRequestError => exc
  puts exc.response_body      # parsed JSON response from the API
  puts exc.response_status    # status code of the response
  puts exc.url                # uri of the API request

  # you normally want this one, a human readable error description
  puts exc.message
end

On instance methods, however, exceptions are handled in a way similar to ActiveRecord. These methods returns a boolean indicating if the API request succeeded or not, and makes the code, description and parameters available when the request fails:

@space_contact = SpaceContact.new({:name => 'The Dude', :birthdate => 50.years.ago})
if @space_contact.create
  # Success
else
  # Error, check:
  # @space_contact.error_code
  # @space_contact.error_message
  # @space_contact.error_parameters
end

Full Example

require 'rubygems'
require 'podio'

Podio.setup(:api_key => 'YOUR_API_KEY', :api_secret => 'YOUR_API_SECRET')
Podio.client.authenticate_with_credentials('YOUR_PODIO_ACCOUNT', 'YOUR_PODIO_PASSWORD')

# Print a list of organizations I'm a member of
my_orgs = Podio::Organization.find_all

my_orgs.each do |org|
  puts org.name
  puts org.url
end

Meta

This project uses Semantic Versioning.

podio-rb's People

Contributors

abutenko94 avatar akikoo avatar albertfdp avatar andreas avatar arunnacitrix avatar ashwinsurendran92 avatar auchenberg avatar bcaccinolo avatar cmchase avatar cpeters avatar daviferreira avatar ddhamnekar avatar deepakncitrix avatar dmatteo avatar haugstrup avatar infinitewarp avatar joshk avatar matthewrossanderson avatar mhrdev avatar munter avatar nemo avatar pjmuller avatar rspace avatar shridharag avatar shubhamgau avatar stengaard avatar sumeetkumarb avatar tbratctrx avatar theflow avatar varghese-7 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  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

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

podio-rb's Issues

NoMethodError (undefined method `post' for nil:NilClass)

Hello,

"NoMethodError (undefined method `post' for nil:NilClass)" shows only in production when the app executes Podio::Item.create, Podio::Search.in_app, etc. I tried to execute the same thing in the production console but it works. Same goes under development environment - the app works fine. My current setup below:

config/initializers/podio.rb
require 'rubygems'
require 'podio'
Podio.setup(:api_key => 'YOUR_API_KEY', :api_secret => 'YOUR_API_SECRET')
Podio.client.authenticate_with_credentials('YOUR_PODIO_ACCOUNT', 'YOUR_PODIO_PASSWORD')

Thanks,

Henry

Outdated Faraday dependency

Hi. Hope you're doing great!

In the project you have a dependency:

s.add_dependency('faraday', ['>= 0.8.0', '< 0.10.0'])

And I want to use podio-rb along with another gem that requires Faraday >= 0.12.0.

Do you have any plans on upgrading Faraday dependency?

Rails 4 support

Hi!

Any chance to make Podio run on Rails 4? It seems completely incompatible for now :(

Ruby 2.1 & 2.2, Getting: Faraday::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

I can connect by setting up an SSL Connection directly just fine, and the node client is working. I think the problem is that the cert store needs to have set_default_paths() executed. Ruby's openssl support does verification, but does not load the default cert stores. No idea why. But to replicate, all I'm doing is, in irb:

require 'podio'
Podio.setup()
Podio.client.authenticate_with_credentials("MY EMAIL", "MY PASSWORD")

Yielding:
Faraday::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

I can connect via ssl though, so long as I call set_default_paths on the cert store.

Note on dependancies for python client library

Is there a wiki to add this to?

If you get this error:

init() got an unexpected keyword argument 'disable_ssl_certificate_validation'

then probably caused by old httplib2 library, to fix:

easy_install -U httplib2

ItemDiff.revert used inside hook causes infinite loop

When a user updates a field on an item in Podio, an update hook is triggered in my app. Thing is, there are a couple fields that I don't want changed at all. Since there's no read-only option per field, I'm trying to use the revert function, but it constantly throws an infinite loop. Is there any way to prevent this?
I'm using Ruby.

ex:
when 'item.update'
(setup code)
if label == 'Project'
Podio::ItemDiff.revert(@item_id, @curr_rev)
end
end

Faraday dependency making this gem tough for new apps

The current faraday gem is v2.9.x, and for a newer application using common gems that depend on faraday require >2 now. This dependency <= 1.3.0 makes is infeasible to use podio-rb.

s.add_dependency('faraday', ['>= 0.8.0', '<= 1.3.0'])

Please consider updating the gem to work with faraday v2+.

Unable to run example

When I try to run the sample-app with my app id and secret, after clicking the try to authorize link, I get the following error:

undefined method `authorize_url' for nil:NilClass

The line causing the error:

 redirect Podio.client.authorize_url(:redirect_uri => redirect_uri)

When inspecting the app with RubyMine, the error seems to happen in

Faraday::Connection.new(:url => api_url, :headers => configured_headers, :request => {:client => self}) do |builder| 

Can you give me any hint?

Using OS X 10.9, ruby-2.0.0p247 and the latest podia-gem.

Tag versions

Podio is great, having an API is even greater, and opensourcing the client connector... ok, you understood my point.

However, this would be nice to have tags in your Github repo matching the versions on Rubygems. I would feel a lot more confident with that...

Why thread locals?

Podio uses thread locals to store the client. Is there a reason for doing that instead of standard instance variables? I ask because it causes problems on certain servers.

Rate limit information

I'm currently running into API rate limits during testing of my app. It would be really cool to be able to interrogate the Podio object for information about how many calls are left for a given API endpoint.

I believe this information could be gathered from the response headers as explained here: https://developers.podio.com/index/limits

Certificate verify failed

I am trying to play around with podio gem. When I call Podio.setup and pass my api keys it does not give me any error but after that when I try to authenticate Podio.client and pass my username and password I get the following error

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

faraday 0.9.0?

Hello. I have written integration with podio, chef and consul-templates. The consul integration is using the diplomat rubygem, which is written with a faraday 0.9.0 dependency.

Do you have plans to upgrade to faraday 0.9.0? Is that on your roadmap?

Using this gem in a multi-user system

My app has many users. Each of them has their own Podio credentials, which I allow them to define using the podio-ominauth strategy.

I am a bit alarmed that the models in this gem all use the singleton method Podio.connection to issue API calls to Podio. This appears to use whichever user's credentials were last passed to Podio.setup.

I may be misunderstanding the architecture of this gem. Please reassure me that I am wrong about this and my many users will not be seeing each others' data in my app.

error on adding podio gem to project

/Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/core_ext/module/deprecation.rb:21:in `deprecate': uninitialized constant ActiveSupport::Deprecation (NameError)
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/core_ext/class/delegating_attributes.rb:26:in `<class:Class>'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/core_ext/class/delegating_attributes.rb:6:in `<top (required)>'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/backports-3.6.4/lib/backports/std_lib.rb:9:in `require'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/backports-3.6.4/lib/backports/std_lib.rb:9:in `require_with_backports'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/core_ext/class.rb:2:in `<top (required)>'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/backports-3.6.4/lib/backports/std_lib.rb:9:in `require'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/backports-3.6.4/lib/backports/std_lib.rb:9:in `require_with_backports'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/core_ext.rb:2:in `block in <top (required)>'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/core_ext.rb:1:in `each'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/core_ext.rb:1:in `<top (required)>'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/backports-3.6.4/lib/backports/std_lib.rb:9:in `require'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/backports-3.6.4/lib/backports/std_lib.rb:9:in `require_with_backports'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/podio-1.0.0/lib/podio.rb:2:in `<top (required)>'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/backports-3.6.4/lib/backports/std_lib.rb:9:in `require'
    from /Users/robertshippey/.rvm/gems/ruby-2.2.2/gems/backports-3.6.4/lib/backports/std_lib.rb:9:in `require_with_backports'
    from /Users/robertshippey/Desktop/status/jobs/podio.rb:2:in `<top (required)>'
...

I'm new to Ruby and I don't really know what this means. I'm using ruby-2.2.2 and my only other dependancies are dashing and httparty. I had a look and there was an issue already on here, #16, which looked relevant but apparently fixed so I'm unsure.

Versioning and Tagging?

You've stated that you follow semantic versioning, but it seems like it's been a long while since a tag has been added to this repo. We use this gem in our app and need to pin a specific version. We'd prefer to use a tag rather than a SHA.

"Active Podio" & custom attributes

From the README: "... all find methods return model instances with attributes cast to the expected type (string, integer, boolean, datetime, etc.)"

I have a Podio::Item instance, and am trying to get at custom attributes (for example location), but I get NoMethodError: undefined method 'location' for #<Podio::Item:0x007f03db573010>. Using a default attribute such as title seems to work.

What can the problem be?

Podio API & gem still alive?

I'm trying to write code using the Podio API and this gem, but I'm finding it difficult to get a response from Podio/Cisco developers.

Questions on StackOverflow are answered by inexperienced staff if at all.

Issues raised here are ignored.

I don't think my questions or suggestions are unreasonable and it's difficult to contemplate continuing to use Podio if the API is a stale project unsupported by Cisco.

@theflow @RSpace: Sorry to bug you but do you know of anybody I can contact to find out whether the API is still supported by Cisco?

'certificate verify failed' on heroku

all API calls fail with

OpenSSL::SSL::SSLError - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

on Heroku using Ruby 1.8.7

Documentation inconsistencies regarding Content-Type for authenticate_with_app

The podio documentation here: https://developers.podio.com/authentication/app_auth outlines the POST:

HTTP METHOD: POST URL: https://api.podio.com/oauth/token/v2 HEADER: "Content-Type: application/json" BODY: { "grant_type": "app", "app_id": YOUR_PODIO_APP_ID, "app_token": YOUR_PODIO_APP_TOKEN, "client_id": YOUR_CLIENT_ID, "redirect_uri": YOUR_URL, "client_secret": YOUR_CLIENT_SECRET }

However the the podio ruby client found here: https://github.com/podio/podio-rb/blob/master/lib/podio/client.rb#L96 uses req.headers['Content-Type'] = 'application/x-www-form-urlencoded'.

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.