osrc 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09a60de82231f1c0461083a7b460134a5a7c3f35
4
- data.tar.gz: 9a07ed509fc93262e6c7674f27603da448048352
3
+ metadata.gz: 73eab32e6abb608d18688d4e51ece1d20f3423f2
4
+ data.tar.gz: c2ed5096ededdd3c3c66904dc686ced680ceb6b7
5
5
  SHA512:
6
- metadata.gz: d9c8a567bb226f404522ff207c5c2bcbc6662a3be7de4469274f8c0198a05e35117517ec31d94931deb2037c87a07a0c164a75a657956afd3990e48142db21ba
7
- data.tar.gz: 5657580cb5d21f80b483a0b5feae10d2d64bc3911cf368d8d12eda06a263e4ae7003bdc399ce5214f5c8b59b5caa3f2b9b216ec0d88930776d17d048b400284c
6
+ metadata.gz: 0c3934f4dc25680a5cb803d4c70211e5ccdfa9b3eaa5a034ac49420fe06a608379c578e6dfd8c24edfb5b35cbaf00131d40f9105236cd0a6e61cb8cf68ab8c5d
7
+ data.tar.gz: 4618bb280a6ad76b4ef1adaebebe005422772ebf473740ddcf6a2927fa11b3b1b08581f8b76a5519a5ea2a59dd0fd61d5d01118f4281d796543654d43d6cbd10
@@ -1,5 +1,5 @@
1
1
  require "osrc/version"
2
- require 'osrc/connection.rb'
2
+ require 'osrc/connection'
3
3
 
4
4
  module Osrc
5
5
  # Your code goes here...
@@ -0,0 +1,56 @@
1
+ require 'osrc/http_exception.rb'
2
+ require 'osrc/parse_json.rb'
3
+
4
+ module Osrc
5
+ class Connection
6
+ @response = {}
7
+ def initialize(git_username)
8
+ @connection ||= Faraday.new(:url => 'http://osrc.dfm.io') do |f|
9
+ f.request :url_encoded # form-encode POST params
10
+ f.response :logger # log requests to STDOUT
11
+ f.adapter Faraday.default_adapter # make requests with Net::HTTP
12
+
13
+ f.use Osrc::ParseJSON
14
+ f.use Osrc::HttpException
15
+ end
16
+
17
+ response = @connection.get "/#{git_username}.json"
18
+ @response = response.body
19
+ end
20
+
21
+ # returns response body
22
+ def response_body
23
+ @response
24
+ end
25
+
26
+ # returns all connected users
27
+ def connected_users
28
+ @response["connected_users"] rescue []
29
+ end
30
+
31
+ # returns repositories
32
+ def repositories
33
+ @response["repositories"] rescue []
34
+ end
35
+
36
+ # returns similar users
37
+ def similar_users
38
+ @response["similar_users"] rescue []
39
+ end
40
+
41
+ # returns usage stat
42
+ def usage
43
+ @response["usage"] rescue {}
44
+ end
45
+
46
+ # returns languages
47
+ def languages
48
+ @response["usage"]["languages"].map {|l| l["language"] } rescue []
49
+ end
50
+
51
+ # returns username
52
+ def username
53
+ @response["username"] rescue ''
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,31 @@
1
+ require 'faraday'
2
+
3
+ module Osrc
4
+ class BadRequest < StandardError; end
5
+ class Unauthorized < StandardError; end
6
+ class RequestFailed < StandardError; end
7
+ class Forbidden < StandardError; end
8
+ class NotFound < StandardError; end
9
+ class ServerError < StandardError; end
10
+
11
+ class HttpException < Faraday::Response::Middleware
12
+ def call(env)
13
+ @app.call(env).on_complete do |response|
14
+ case response[:status].to_i
15
+ when 400
16
+ raise Osrc::BadRequest, 'Often missing a required parameter'
17
+ when 401
18
+ raise Osrc::Unauthorized, 'No valid API key provided'
19
+ when 402
20
+ raise Osrc::RequestFailed, 'Parameters were valid but the request failed'
21
+ when 403
22
+ raise Osrc::Forbidden, 'The API key is not valid for that request'
23
+ when 404
24
+ raise Osrc::NotFound, 'The requested item doesn\'t exist'
25
+ when 500..505
26
+ raise Osrc::ServerError, 'Something went wrong on Osrc\'s side'
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ require 'json'
2
+
3
+ module Osrc
4
+ class ParseJSON < Faraday::Response::Middleware
5
+ def on_complete(env)
6
+ env[:body] = JSON.parse(env[:body])
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Osrc
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osrc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - vajapravin
@@ -74,14 +74,14 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - ".gitignore"
78
77
  - Gemfile
79
- - LICENSE.txt
80
78
  - README.md
81
79
  - Rakefile
82
80
  - lib/osrc.rb
81
+ - lib/osrc/connection.rb
82
+ - lib/osrc/http_exception.rb
83
+ - lib/osrc/parse_json.rb
83
84
  - lib/osrc/version.rb
84
- - osrc.gemspec
85
85
  homepage: https://github.com/vajapravin/osrc
86
86
  licenses:
87
87
  - MIT
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 vajapravin
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'osrc/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "osrc"
8
- spec.version = Osrc::VERSION
9
- spec.authors = ["vajapravin"]
10
- spec.email = ["vajapravin23@gmail.com"]
11
- spec.summary = %q{Using GitHub username to see a dynamically generated progress report for their open source contributions.}
12
- spec.description = %q{The Open Source Report Card(osrc) is an open source project developed on GitHub and licensed under the MIT License.}
13
- spec.homepage = "https://github.com/vajapravin/osrc"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.5"
22
- spec.add_development_dependency "rake", "~> 0"
23
- spec.add_development_dependency 'faraday', "~> 0"
24
- spec.add_development_dependency 'mime-types', "~> 0"
25
-
26
- end