Class: HackOne
- Inherits:
-
Object
show all
- Defined in:
- lib/hackone.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url) ⇒ HackOne
Returns a new instance of HackOne.
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
54
55
56
57
58
|
# File 'lib/hackone.rb', line 27
def initialize(url)
if url.include? "http://" or url.include? "https://"
url += "?api_key=#{HackOne.api_key}" if HackOne.api_key != ""
body = open(url)
contents = body.read
else
file = File.open("data.json", "rb")
contents = file.read
end
begin
@result = cleanse(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
@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
106
107
108
109
110
111
112
113
|
# File 'lib/hackone.rb', line 106
def method_missing(method, *args, &block)
attr = method.to_s
if @result
@result[attr]
else
super
end
end
|
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
13
14
15
|
# File 'lib/hackone.rb', line 13
def email
@email
end
|
#is_private ⇒ Object
Returns the value of attribute is_private.
13
14
15
|
# File 'lib/hackone.rb', line 13
def is_private
@is_private
end
|
#lastUpdated ⇒ Object
Returns the value of attribute lastUpdated.
13
14
15
|
# File 'lib/hackone.rb', line 13
def lastUpdated
@lastUpdated
end
|
#shirtSize ⇒ Object
Returns the value of attribute shirtSize.
13
14
15
|
# File 'lib/hackone.rb', line 13
def shirtSize
@shirtSize
end
|
#username ⇒ Object
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
|
.parse(url) ⇒ Object
23
24
25
|
# File 'lib/hackone.rb', line 23
def self.parse(url)
new(url)
end
|
Instance Method Details
#bio ⇒ Object
A method to help extract the bio part of the application “fields”, returns a list of fields
82
83
84
|
# File 'lib/hackone.rb', line 82
def bio
return @result[:bio]
end
|
#education ⇒ Object
86
87
88
|
# File 'lib/hackone.rb', line 86
def education
return @result[:education]
end
|
#fetch(parent, method) ⇒ Object
A helper method. All the names methods use it to interact with the named method
70
71
72
73
74
75
76
77
|
# File 'lib/hackone.rb', line 70
def fetch(parent,method)
item = @result[parent][method]
if item != nil
return item
else
return "Error: Cannot find this field."
end
end
|
#hackathons ⇒ Object
94
95
96
|
# File 'lib/hackone.rb', line 94
def hackathons
return @result[:hackathons]
end
|
#private? ⇒ Boolean
60
61
62
|
# File 'lib/hackone.rb', line 60
def private?
@is_private
end
|
#projects ⇒ Object
98
99
100
|
# File 'lib/hackone.rb', line 98
def projects
return @result[:projects]
end
|
#public? ⇒ Boolean
64
65
66
|
# File 'lib/hackone.rb', line 64
def public?
!@is_private
end
|
#skills ⇒ Object
102
103
104
|
# File 'lib/hackone.rb', line 102
def skills
return @result[:skills]
end
|
#work ⇒ Object
90
91
92
|
# File 'lib/hackone.rb', line 90
def work
return @result[:work]
end
|