Skip to content

Commit

Permalink
Merge pull request #12 from Fullscreen/add-find-by-id
Browse files Browse the repository at this point in the history
Retrieve an Instagram User by id
  • Loading branch information
jcohenho committed Aug 13, 2015
2 parents 69adcfe + 8b5bda3 commit f595373
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ If it does, then replace your calls to `followers_count` with `follower_count` (
## 0.2.2 - 2015-08-04

* [FEATURE] Add `Facebook::Page` supporting `find_by` and `find_by!`.

## 0.2.3 - 2015-08-12

* [FEATURE] Add `find_by id: [Integer] and find_by! id: [Integer] to Instagram::User`.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ Net::Instagram::User
Use [Net::Instagram::User]() to:

* retrieve an Instagram user by username
* retrieve an Instagram user by id
* access the number of followers of an Instagram user
* access the number of following of an Instagram user

```ruby
user = Net::Instagram::User.find_by username: 'fullscreen'
user.follower_count #=> 7025
user.follower_count #=> 24198

user = Net::Instagram::User.find_by id: 270587948
user.follower_count #=> 24198
```

*The methods above require a configured Instagram app (see below).*
Expand Down
11 changes: 11 additions & 0 deletions lib/net/instagram/api/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ def query
query.merge! client_id: Net::Instagram.configuration.client_id
end.to_param
end

def as_curl
'curl'.tap do |curl|
curl << " -X #{http_request.method}"
http_request.each_header do |name, value|
curl << %Q{ -H "#{name}: #{value}"}
end
curl << %Q{ -d '#{http_request.body}'} if http_request.body
curl << %Q{ "#{@uri.to_s}"}
end
end
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/net/instagram/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ def self.find_by(params = {})
# @param [Hash] params the attributes to find a user by.
# @option params [String] :username The Instagram user’s username
# (case-insensitive).
# @option params [String] :id The Instagram user’s id
# (case-insensitive).
# @raise [Net::Errors::PrivateUser] if the user account is private.
def self.find_by!(params = {})
find_by_username! params[:username]
if params[:username]
find_by_username! params[:username]
elsif params[:id]
find_by_id! params[:id]
end
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/net/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Net
VERSION = "0.2.2"
VERSION = "0.2.3"
end

0 comments on commit f595373

Please sign in to comment.