hackone 0.0.1

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 +15 -0
  2. data/lib/hackone.rb +99 -0
  3. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODFjOWZiZTJkNWJhYzE4NzE1NTA2NzVkNzhlNGIwMDNiMTk2YWVkNw==
5
+ data.tar.gz: !binary |-
6
+ OTk0NDkzNWIwZGZkYjZlYTY3MmM1ODM3NDMyMDcyYTUzMDU3MjVlYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NzY3MzhkMjA4MGRmMzYwMzQ0MGE3MDU5ODEyMzQwOWJiY2UwODhhOGZlOWM0
10
+ MmVlNTg1YWJmMjI5ZDE4MzVmNjYyMzBmZTllNGQyODE3YzRmZWRmY2I0NTdj
11
+ NTk5MDEwMzNkZTM3YmYzZjFmNWEzMzhlNTE4OTZjNDZkMjZhNmI=
12
+ data.tar.gz: !binary |-
13
+ YjA1ZWI1YmMxOTNmZDIzZTk3MDQyNmJjMzAwZGYyNGY4ZjU4ZmQzZGMwZTdi
14
+ YjMzNmRhNjkyZmVlM2I1NzljYWM3N2RkMjNhYTg0MmU2YjQ2MDJkMTc3Njcw
15
+ MzA1OWYwYTA4NzRhYjIzZGMyNTgwNWI0ZmY4NzEyYTY3YjYwZDQ=
data/lib/hackone.rb ADDED
@@ -0,0 +1,99 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ # Built from the great work of Marcus Yearwood.
5
+ # Original repository: https://github.com/myearwood
6
+
7
+ class HackOneException < Exception; end
8
+ class HackOneInvalidAPIKey < Exception; end
9
+ class HackOneUserNotFound < Exception; end
10
+ class HackOneInvalidCommonHackDocument < Exception; end
11
+
12
+ class HackOne
13
+ attr_reader :username, :email, :lastUpdated, :is_private, :shirtSize
14
+
15
+ def self.api_key=(api_key)
16
+ @api_key = api_key
17
+ end
18
+
19
+ def self.api_key
20
+ @api_key || ""
21
+ end
22
+
23
+ def initialize(url)
24
+ if url.include? "http://" or url.include? "https://"
25
+ body = open(url)
26
+ contents = body.read
27
+ else
28
+ #its a local file, so use File.Read
29
+ file = File.open("data.json", "rb")
30
+ contents = file.read
31
+ end
32
+
33
+ begin
34
+ @result = JSON.parse(contents)
35
+ rescue
36
+ raise HackOneInvalidCommonHackDocument
37
+ end
38
+
39
+ if @result["error"] == "user_not_found"
40
+ raise HackOneUserNotFound
41
+ end
42
+
43
+ if @result["error"] == "api_key_invalid"
44
+ raise HackOneInvalidAPIKey
45
+ end
46
+
47
+ # Basic level.
48
+ @username = @result["username"]
49
+ @email = @result["email"]
50
+ @lastUpdated = @result["lastUpdated"]
51
+ @shirtSize = @result["shirtSize"]
52
+ @is_private = @result["private"]
53
+ end
54
+
55
+
56
+ # A helper method. All the names methods use it to
57
+ # interact with the named method
58
+ def fetch(parent,method)
59
+ item = @result[parent][method]
60
+ if item != nil
61
+ return item
62
+ else
63
+ return "Error: Cannot find this field."
64
+ end
65
+ end
66
+
67
+
68
+ # A method to help extract the bio part of the application
69
+ # "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
88
+
89
+ end
90
+
91
+ def method_missing(method, *args, &block)
92
+ attr = method.to_s
93
+ if @result
94
+ @result[attr]
95
+ else
96
+ super
97
+ end
98
+ end
99
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hackone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcus Yearwood
8
+ - Bilawal Hameed
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-03 00:00:00.000000000 Z
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
17
+ email: bilawal@hackcard.org
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/hackone.rb
23
+ homepage: http://github.com/hackcard/hackone
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.1.9
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: A gem to use for parsing CommonHack & HackOne JSON docs.
47
+ test_files: []
48
+ has_rdoc: