hackone 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/hackone.rb +51 -24
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODFjOWZiZTJkNWJhYzE4NzE1NTA2NzVkNzhlNGIwMDNiMTk2YWVkNw==
4
+ YjM1MDBhOTgyZTI4OGUwNzIyMzE4MTIwOWFiY2JhZmZhNTEwYTQ0Nw==
5
5
  data.tar.gz: !binary |-
6
- OTk0NDkzNWIwZGZkYjZlYTY3MmM1ODM3NDMyMDcyYTUzMDU3MjVlYQ==
6
+ YWM2NmQxYTNiY2FlMDI2N2NkOWU1YWQ3ZmQyNTRlZmQ4YTU1NTIxOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzY3MzhkMjA4MGRmMzYwMzQ0MGE3MDU5ODEyMzQwOWJiY2UwODhhOGZlOWM0
10
- MmVlNTg1YWJmMjI5ZDE4MzVmNjYyMzBmZTllNGQyODE3YzRmZWRmY2I0NTdj
11
- NTk5MDEwMzNkZTM3YmYzZjFmNWEzMzhlNTE4OTZjNDZkMjZhNmI=
9
+ YjQ1YjcwM2EyOGQ5N2E4Y2JjNzAxMzVhZWM2ZWQ0MGY3MTgzY2JkZjY0NzBl
10
+ ODI1NDM2NmMzNjhhZTY1ZTJjNzM4NWUwZjkwYWRhNTJmNTQ5NTBiZWNjMzdh
11
+ M2UzMjE5NGExZDgzZjRhODlmNzRmNDcxM2E0ZTYxNWYyM2QwMjk=
12
12
  data.tar.gz: !binary |-
13
- YjA1ZWI1YmMxOTNmZDIzZTk3MDQyNmJjMzAwZGYyNGY4ZjU4ZmQzZGMwZTdi
14
- YjMzNmRhNjkyZmVlM2I1NzljYWM3N2RkMjNhYTg0MmU2YjQ2MDJkMTc3Njcw
15
- MzA1OWYwYTA4NzRhYjIzZGMyNTgwNWI0ZmY4NzEyYTY3YjYwZDQ=
13
+ Nzc0YzFmYjZkYjczNTQwYzQyNDQxYmM0NTIzYTNjMjMyNTRmODM3NzYwMDgx
14
+ OWUyMzg3OGRkOGQ4NGVkMzEzODY1Y2M2YjA3Nzk2YWYwZjFmMDMxNTQ4NzAx
15
+ OTMwOTEwODI3Mjc0OGNiNDQ5MzBiM2VlZjM0ODFjMzk0OTU0MWI=
@@ -20,8 +20,13 @@ class HackOne
20
20
  @api_key || ""
21
21
  end
22
22
 
23
+ def self.parse(url)
24
+ new(url)
25
+ end
26
+
23
27
  def initialize(url)
24
28
  if url.include? "http://" or url.include? "https://"
29
+ url += "?api_key=#{HackOne.api_key}" if HackOne.api_key != ""
25
30
  body = open(url)
26
31
  contents = body.read
27
32
  else
@@ -31,7 +36,7 @@ class HackOne
31
36
  end
32
37
 
33
38
  begin
34
- @result = JSON.parse(contents)
39
+ @result = cleanse(JSON.parse(contents))
35
40
  rescue
36
41
  raise HackOneInvalidCommonHackDocument
37
42
  end
@@ -45,13 +50,20 @@ class HackOne
45
50
  end
46
51
 
47
52
  # Basic level.
48
- @username = @result["username"]
49
- @email = @result["email"]
50
- @lastUpdated = @result["lastUpdated"]
51
- @shirtSize = @result["shirtSize"]
52
- @is_private = @result["private"]
53
+ @username = @result[:username]
54
+ @email = @result[:email]
55
+ @lastUpdated = @result[:lastUpdated]
56
+ @shirtSize = @result[:shirtSize]
57
+ @is_private = @result[:private]
53
58
  end
54
59
 
60
+ def private?
61
+ @is_private
62
+ end
63
+
64
+ def public?
65
+ !@is_private
66
+ end
55
67
 
56
68
  # A helper method. All the names methods use it to
57
69
  # interact with the named method
@@ -67,25 +79,28 @@ class HackOne
67
79
 
68
80
  # A method to help extract the bio part of the application
69
81
  # "fields", returns a list of fields
70
- def bio(method)
71
- if method != "fields"
72
- return fetch("bio", method)
73
- else
74
- return [
75
- "firstName",
76
- "lastName",
77
- "gender",
78
- "email",
79
- "phone",
80
- "dietaryRestrictions",
81
- "summary",
82
- "location",
83
- "websites",
84
- "resume",
85
- "picture"
86
- ]
87
- end
82
+ def bio
83
+ return @result[:bio]
84
+ end
85
+
86
+ def education
87
+ return @result[:education]
88
+ end
88
89
 
90
+ def work
91
+ return @result[:work]
92
+ end
93
+
94
+ def hackathons
95
+ return @result[:hackathons]
96
+ end
97
+
98
+ def projects
99
+ return @result[:projects]
100
+ end
101
+
102
+ def skills
103
+ return @result[:skills]
89
104
  end
90
105
 
91
106
  def method_missing(method, *args, &block)
@@ -96,4 +111,16 @@ class HackOne
96
111
  super
97
112
  end
98
113
  end
114
+
115
+
116
+ private
117
+ def cleanse(h)
118
+ nh = nil
119
+ nh = {} if h.is_a? Hash
120
+ nh = [] if h.is_a? Array
121
+ nh = h if nh.nil?
122
+ h.each { |k, v| nh[k.to_sym] = cleanse(v) } if h.is_a? Hash
123
+ h.each { |k| nh.push(cleanse(k)) } if h.is_a? Array
124
+ nh
125
+ end
99
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hackone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Yearwood
@@ -11,16 +11,16 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2014-09-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: This gem is a ruby wrapper that similifies the parsing CommonHack JSON.
15
- More information about HackOne can be seen at http://www.hackone.co and more information
16
- about CommonHack can be seen at http://commonhack.org
14
+ description: This gem is a ruby wrapper that similifies the parsing CommonHack and
15
+ HackOne JSON. More information about HackOne can be seen at http://www.hackone.co
16
+ and more information about CommonHack can be seen at http://commonhack.org
17
17
  email: bilawal@hackcard.org
18
18
  executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - lib/hackone.rb
23
- homepage: http://github.com/hackcard/hackone
23
+ homepage: http://github.com/hackcard/hackone-ruby
24
24
  licenses:
25
25
  - MIT
26
26
  metadata: {}