Skip to content

Commit

Permalink
Add OAuth example in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
remi committed Apr 30, 2012
1 parent c212c8a commit 388826c
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion README.md
Expand Up @@ -66,7 +66,7 @@ Her doesn’t support any kind of authentication. However, it’s very easy to i
class MyAuthentication < Faraday::Middleware
def call(env)
env[:request_headers]["X-API-Token"] = "bb2b2dd75413d32c1ac421d39e95b978d1819ff611f68fc2fdd5c8b9c7331192"
@all.call(env)
@app.call(env)
end
end

Expand Down Expand Up @@ -107,6 +107,37 @@ Her::API.setup :base_uri => "https://api.example.com", :parse_middleware => MyCu
# User.find(1) will now expect "https://api.example.com/users/1" to return something like '{ "data" => { "id": 1, "name": "Tobias Fünke" }, "errors" => [] }'
```

### OAuth

Using the `faraday_middleware` and `simple_oauth` gems, it’s fairly easy to use OAuth authentication with Her.

In your Gemfile:

```ruby
gem "her"
gem "faraday_middleware"
gem "simple_oauth"
```

In your Ruby code:

```ruby
TWITTER_CREDENTIALS = {
:consumer_key => "",
:consumer_secret => "",
:token => "",
:token_secret => ""
}

Her::API.setup :base_uri => "https://api.twitter.com/1/", :add_middleware => [FaradayMiddleware::OAuth => TWITTER_CREDENTIALS]

class Tweet
include Her::Model
end

@tweets = Tweet.get("/statuses/home_timeline.json")
```

## Relationships

You can define `has_many`, `has_one` and `belongs_to` relationships in your models. The relationship data is handled in two different ways. When parsing a resource from JSON data, if there’s a relationship data included, it will be used to create new Ruby objects.
Expand Down

0 comments on commit 388826c

Please sign in to comment.