commonhack 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 +7 -0
  2. data/lib/commonhack.rb +113 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b2c30362376609a5357ce3c145d5ca917b0cfbc
4
+ data.tar.gz: 414ab52be2be0e69e0b6d75399f8e02d2c864f6a
5
+ SHA512:
6
+ metadata.gz: 54d68c2e020e492a58418e300ccfaa7cb42695eee838d2e177ca041c715a874b52c883e2fe95649aef5f9328cd1b4b3d68e92ea411e860cf6fa712bfcb53575a
7
+ data.tar.gz: 8c3b1186246f2bb81118ab448eb5c303b5db51cf4216fbfea1fe308c521c89f022616b91ab11d756168806d3347d4f1a5eb170ce9249efae64202d3c9838438a
data/lib/commonhack.rb ADDED
@@ -0,0 +1,113 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+
5
+ # graceful error handling
6
+
7
+ class CommonHack
8
+
9
+ #makes these three fields accessable via dot notation
10
+
11
+ attr_reader :username,:email,:lastUpdated
12
+
13
+
14
+ #intitalizes the class
15
+
16
+ def initialize(url)
17
+
18
+
19
+ if url.include? "http://" or url.include? "https://"
20
+ body = open(url)
21
+ contents = body.read
22
+
23
+ else
24
+ #its a local file, so use File.Read
25
+ file = File.open("data.json", "rb")
26
+ contents = file.read
27
+ end
28
+
29
+ @result = JSON.parse(contents)
30
+
31
+ #make the basic first level info accessible
32
+ @username = @result["username"]
33
+ @email = @result["email"]
34
+ @lastUpdated = @result["lastUpdated"]
35
+
36
+ end
37
+
38
+
39
+ # A helper method. All the names methods use it to
40
+ # interact with the named method
41
+
42
+ def fetch(parent,method)
43
+
44
+ item = @result[parent][method]
45
+ if item != nil
46
+ return item
47
+ else
48
+ return "Error: Cannot find this field."
49
+ end
50
+
51
+ end
52
+
53
+
54
+ # A method to help extract the bio part of the application
55
+ # "fields", returns a list of fields
56
+
57
+ def bio(method)
58
+
59
+ if method != "fields"
60
+
61
+ return fetch("bio",method)
62
+
63
+ else
64
+
65
+ return [
66
+ "firstName",
67
+ "lastName",
68
+ "gender",
69
+ "email",
70
+ "phone",
71
+ "dietaryRestrictions",
72
+ "summary",
73
+ "location",
74
+ "websites",
75
+ "resume",
76
+ "picture"
77
+ ]
78
+ end
79
+
80
+ end
81
+
82
+ # These fields return arrays so they pass the array to the user,
83
+ # rather than looping through them
84
+
85
+ def education(method)
86
+
87
+ return @result["education"]
88
+ end
89
+
90
+
91
+ def work()
92
+
93
+ return @result["work"]
94
+ end
95
+
96
+ # hackathons is the same thing
97
+
98
+ def hackathons()
99
+
100
+ return @result["hackathons"]
101
+ end
102
+
103
+ def projects()
104
+
105
+ return @result["projects"]
106
+ end
107
+
108
+ def skills()
109
+
110
+ return @result["skills"]
111
+ end
112
+
113
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commonhack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcus Yearwood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem is a ruby wrapper that similifies the parsing CommonHack JSON.
14
+ More informatino about CommonHack can be found at http://commonhack.org
15
+ email: m.yearwood@live.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/commonhack.rb
21
+ homepage: http://github.com/myearwood/commonhack
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.3.0
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: A gem to use for parsing CommonHack JSON docs.
45
+ test_files: []