Class: UserHttpHandler
- Inherits:
-
Object
- Object
- UserHttpHandler
- Includes:
- HttpHandler
- Defined in:
- lib/github_api_ruby_lib/http/user_http_handler.rb
Constant Summary collapse
- @@app_token =
nil- @@http =
nil
Class Method Summary collapse
- .get_auth_token ⇒ Object
-
.set_auth_token(token) ⇒ Object
Set the authentication token ====Attribute -
token-> token generated that is needed to make authentication calls.
Instance Method Summary collapse
-
#get_response_status ⇒ Object
returns the response status that is true if request was successful.
-
#get_user_followers(params) ⇒ Object
get all the followers of the given user ==== Attributes -
params-> optional parameters for getting followers. -
#initialize ⇒ UserHttpHandler
constructor
A new instance of UserHttpHandler.
-
#search_for_user(params) ⇒ Object
Search and retrieve user information based on search parameters ==== Attributes -
params-> optional filters for getting users. -
#search_for_user_email(username) ⇒ Object
Search for email address of user ==== Attributes -
username-> username id to get email.
Methods included from HttpHandler
create_http, get_response, initiate_http
Constructor Details
#initialize ⇒ UserHttpHandler
Returns a new instance of UserHttpHandler.
12 13 14 15 |
# File 'lib/github_api_ruby_lib/http/user_http_handler.rb', line 12 def initialize @response_status=false @uri_builder=UriBuilder.new end |
Class Method Details
.get_auth_token ⇒ Object
25 26 27 |
# File 'lib/github_api_ruby_lib/http/user_http_handler.rb', line 25 def self.get_auth_token @@app_token end |
.set_auth_token(token) ⇒ Object
Set the authentication token
Attribute
-
token-> token generated that is needed to make authentication calls
21 22 23 |
# File 'lib/github_api_ruby_lib/http/user_http_handler.rb', line 21 def self.set_auth_token (token) @@app_token=token end |
Instance Method Details
#get_response_status ⇒ Object
returns the response status that is true if request was successful
94 95 96 |
# File 'lib/github_api_ruby_lib/http/user_http_handler.rb', line 94 def get_response_status @response_status end |
#get_user_followers(params) ⇒ Object
get all the followers of the given user
Attributes
-
params-> optional parameters for getting followers
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/github_api_ruby_lib/http/user_http_handler.rb', line 32 def get_user_followers(params) # :yields: JSON uri=URI.parse(@uri_builder.get_user_contents(::USER::FOLLOWERS,username:params[:username], token:@@app_token)) http=HttpHandler.initiate_http(uri) begin if @@app_token == nil raise "Authentication not provided" end response=HttpHandler.get_response(http,uri) rescue ArgumentError puts "Request failed with code: #{response.code}" else @response_status=true return response end end |
#search_for_user(params) ⇒ Object
Search and retrieve user information based on search parameters
Attributes
-
params-> optional filters for getting users
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/github_api_ruby_lib/http/user_http_handler.rb', line 53 def search_for_user(params) # :yields: JSON uri=URI.parse(@uri_builder.get_user_contents(::USER::SEARCH, params)) http=HttpHandler.initiate_http(uri) begin response=HttpHandler.get_response(http,uri) rescue ArgumentError puts "Request failed with code: #{response.code}" else @response_status=true return response end end |
#search_for_user_email(username) ⇒ Object
Search for email address of user
Attributes
-
username-> username id to get email
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/github_api_ruby_lib/http/user_http_handler.rb', line 71 def search_for_user_email(username) # :yields: JSON begin if @@app_token == nil raise "Authentication not provided" end uri=URI.parse(@uri_builder.get_user_contents(::USER::EMAIL,username:username, app_token:@@app_token)) @uri_builder=nil HttpHandler.create_http uri response=HttpHandler.get_response(@@http,uri) @response_status=true return response end end |