Class: HackOne
- Inherits:
-
Object
- Object
- HackOne
- Defined in:
- lib/hackone.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#is_private ⇒ Object
readonly
Returns the value of attribute is_private.
-
#lastUpdated ⇒ Object
readonly
Returns the value of attribute lastUpdated.
-
#shirtSize ⇒ Object
readonly
Returns the value of attribute shirtSize.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
-
#bio(method) ⇒ Object
A method to help extract the bio part of the application “fields”, returns a list of fields.
-
#fetch(parent, method) ⇒ Object
A helper method.
-
#initialize(url) ⇒ HackOne
constructor
A new instance of HackOne.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(url) ⇒ HackOne
Returns a new instance of HackOne.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hackone.rb', line 23 def initialize(url) if url.include? "http://" or url.include? "https://" body = open(url) contents = body.read else #its a local file, so use File.Read file = File.open("data.json", "rb") contents = file.read end begin @result = JSON.parse(contents) rescue raise HackOneInvalidCommonHackDocument end if @result["error"] == "user_not_found" raise HackOneUserNotFound end if @result["error"] == "api_key_invalid" raise HackOneInvalidAPIKey end # Basic level. @username = @result["username"] @email = @result["email"] @lastUpdated = @result["lastUpdated"] @shirtSize = @result["shirtSize"] @is_private = @result["private"] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/hackone.rb', line 91 def method_missing(method, *args, &block) attr = method.to_s if @result @result[attr] else super end end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
13 14 15 |
# File 'lib/hackone.rb', line 13 def email @email end |
#is_private ⇒ Object (readonly)
Returns the value of attribute is_private.
13 14 15 |
# File 'lib/hackone.rb', line 13 def is_private @is_private end |
#lastUpdated ⇒ Object (readonly)
Returns the value of attribute lastUpdated.
13 14 15 |
# File 'lib/hackone.rb', line 13 def lastUpdated @lastUpdated end |
#shirtSize ⇒ Object (readonly)
Returns the value of attribute shirtSize.
13 14 15 |
# File 'lib/hackone.rb', line 13 def shirtSize @shirtSize end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
13 14 15 |
# File 'lib/hackone.rb', line 13 def username @username end |
Class Method Details
.api_key ⇒ Object
19 20 21 |
# File 'lib/hackone.rb', line 19 def self.api_key @api_key || "" end |
.api_key=(api_key) ⇒ Object
15 16 17 |
# File 'lib/hackone.rb', line 15 def self.api_key=(api_key) @api_key = api_key end |
Instance Method Details
#bio(method) ⇒ Object
A method to help extract the bio part of the application “fields”, returns a list of fields
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/hackone.rb', line 70 def bio(method) if method != "fields" return fetch("bio", method) else return [ "firstName", "lastName", "gender", "email", "phone", "dietaryRestrictions", "summary", "location", "websites", "resume", "picture" ] end end |
#fetch(parent, method) ⇒ Object
A helper method. All the names methods use it to interact with the named method
58 59 60 61 62 63 64 65 |
# File 'lib/hackone.rb', line 58 def fetch(parent,method) item = @result[parent][method] if item != nil return item else return "Error: Cannot find this field." end end |