Permalink
Browse files

Add OAuth example in documentation

  • Loading branch information...
1 parent c212c8a commit 388826c2686c34aab866db81d3b0d87b93afcdbd @remiprev committed Apr 30, 2012
Showing with 32 additions and 1 deletion.
  1. +32 −1 README.md
View
@@ -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
@@ -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.

0 comments on commit 388826c

Please sign in to comment.