coder_wally 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cf939f86aad4d6f1ce5aa03e17184d795aaa8bb
4
- data.tar.gz: f75e93d278d3510d99a28fc075f5bb55ed256738
3
+ metadata.gz: defc173143b93f0b93406ef1fbde0900e59cdd76
4
+ data.tar.gz: ee23f5c2797c6b113101b36eb5d5bcfa5be40186
5
5
  SHA512:
6
- metadata.gz: 7c309c97c0c4040b07d37f8077c86f714f8c590f6a1d734fc9ba1fcc82b55bad408de96eae1960fc234423d2da1a30718a2734056b5ab0001a70c42ae6919b5c
7
- data.tar.gz: 339719bdaa06eb7924e3137b1b8f7ca2d6a469bb01203d8d49954bffb051158ce55b49d5a43c0556f24c81f0ddbd036ce105667a3915fe4be270a9ded057a26a
6
+ metadata.gz: 2152878afffe135df1d5c128098ff2237a8b261d86884d443f01304986742d9f5fba42272b28db9bc9d77770dfb996b2ffbefa5c604d82c44ff33d75f1de6ec9
7
+ data.tar.gz: 9a683a6c26b92ed98881dd96f3193fd2c843d5bf205909a4d83a2659a6a9ad1c80e07bbca9c3ced983b6bd2fe4bce68674a57ccac9b7dcb786e10d2163bc8a46
@@ -0,0 +1,13 @@
1
+ # All code in the gem is namespaced under this module.
2
+ module CoderWally
3
+ # Stores the users accounts
4
+ class Account
5
+ # Dynamically create account properties
6
+ def initialize(collection_of_accounts)
7
+ collection_of_accounts.each do |account, value|
8
+ singleton_class.class_eval do; attr_accessor "#{account}"; end
9
+ self.instance_variable_set("@#{account}", value)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -7,10 +7,10 @@ module CoderWally
7
7
 
8
8
  # Initialise object with a hash of values
9
9
  def initialize(hashed_badge)
10
- @name = hashed_badge.fetch("name")
11
- @badge = hashed_badge.fetch("badge")
12
- @description = hashed_badge.fetch("description")
13
- @created = hashed_badge.fetch("created")
10
+ @name = hashed_badge.fetch('name')
11
+ @badge = hashed_badge.fetch('badge')
12
+ @description = hashed_badge.fetch('description')
13
+ @created = hashed_badge.fetch('created')
14
14
  end
15
15
  end
16
16
  end
@@ -48,10 +48,11 @@ module CoderWally
48
48
  json_response = JSON.load(send_request(uri_for_user(username)))
49
49
 
50
50
  badges = json_response['badges'].map { |badge| Badge.new(badge) }
51
+ accounts = Account.new(json_response['accounts'])
51
52
  user = User.new(json_response['name'], json_response['username'],
52
- json_response['location'], json_response['team'])
53
+ json_response['location'], json_response['team'], json_response['endorsements'])
53
54
 
54
- CoderWall.new badges, user
55
+ CoderWall.new badges, user, accounts
55
56
  end
56
57
  end
57
58
  end
@@ -4,12 +4,14 @@ module CoderWally
4
4
  class CoderWall
5
5
  # :badges is the collection of user badges
6
6
  # :user is the `User` object
7
- attr_reader :badges, :user
7
+ # :accounts is the `Account` object
8
+ attr_reader :badges, :user, :accounts
8
9
 
9
10
  # Instantiate the class with data
10
- def initialize(badges, user)
11
+ def initialize(badges, user, accounts)
11
12
  @badges = badges
12
13
  @user = user
14
+ @accounts = accounts
13
15
  end
14
16
  end
15
17
  end
@@ -3,14 +3,15 @@ module CoderWally
3
3
  # Stores user properties
4
4
  class User
5
5
  # Object properties
6
- attr_reader :name, :username, :location, :team
6
+ attr_reader :name, :username, :location, :team, :endorsements
7
7
 
8
8
  # Initialise object with a hash of values
9
- def initialize(name, username, location, team)
9
+ def initialize(name, username, location, team, endorsements)
10
10
  @name = name
11
11
  @username = username
12
12
  @location = location
13
13
  @team = team
14
+ @endorsements = endorsements
14
15
  end
15
16
  end
16
17
  end
@@ -1,4 +1,4 @@
1
1
  module CoderWally
2
2
  # The current version of CoderWally.
3
- VERSION = "0.0.6"
3
+ VERSION = '0.0.7'
4
4
  end
data/lib/coder_wally.rb CHANGED
@@ -1,5 +1,7 @@
1
- require "coder_wally/version"
2
- require "coder_wally/badge"
3
- require "coder_wally/user"
4
- require "coder_wally/coder_wall"
5
- require "coder_wally/client"
1
+ require 'coder_wally/version'
2
+ require 'coder_wally/badge'
3
+ require 'coder_wally/user'
4
+ require 'coder_wally/account'
5
+ require 'coder_wally/coder_wall'
6
+ require 'coder_wally/client'
7
+
@@ -0,0 +1,13 @@
1
+ require 'minitest/autorun'
2
+ require 'coder_wally/account'
3
+
4
+ describe 'Account' do
5
+ it 'creates an account object with dynamic attributes' do
6
+ json_parsed = {'github' => 'gregstewart', 'twitter' => '_greg_stewart_'}
7
+
8
+ account = CoderWally::Account.new(json_parsed)
9
+
10
+ account.github.must_equal 'gregstewart'
11
+ account.twitter.must_equal '_greg_stewart_'
12
+ end
13
+ end
@@ -1,7 +1,7 @@
1
- require "minitest/autorun"
2
- require "coder_wally"
1
+ require 'minitest/autorun'
2
+ require 'coder_wally'
3
3
 
4
- describe "Coder Wally" do
4
+ describe 'Coder Wally' do
5
5
  before do
6
6
  @client = CoderWally::Client.new
7
7
  end
@@ -85,7 +85,8 @@ describe "Coder Wally" do
85
85
  user.name.must_equal 'Greg Stewart'
86
86
  user.username.must_equal 'gregstewart'
87
87
  user.location.must_equal 'London, UK'
88
- user.team.must_equal nil
88
+ user.team.must_be_nil
89
+ user.endorsements.must_be_kind_of Integer
89
90
  end
90
91
  end
91
92
 
@@ -111,6 +112,10 @@ describe "Coder Wally" do
111
112
  @coder_wall.badges.count.must_equal 11
112
113
  @coder_wall.badges.first.must_be_instance_of CoderWally::Badge
113
114
  end
115
+
116
+ it 'has an accounts property' do
117
+ @coder_wall.accounts.must_be_instance_of CoderWally::Account
118
+ end
114
119
  end
115
120
 
116
121
  end
@@ -5,7 +5,8 @@
5
5
  "endorsements": 0,
6
6
  "team": null,
7
7
  "accounts": {
8
- "github": "gregstewart"
8
+ "github": "gregstewart",
9
+ "twitter": "_greg_stewart_"
9
10
  },
10
11
  "badges": [{
11
12
  "name": "Lab",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coder_wally
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-01 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,11 +85,13 @@ files:
85
85
  - bin/coder_wally
86
86
  - coder_wally.gemspec
87
87
  - lib/coder_wally.rb
88
+ - lib/coder_wally/account.rb
88
89
  - lib/coder_wally/badge.rb
89
90
  - lib/coder_wally/client.rb
90
91
  - lib/coder_wally/coder_wall.rb
91
92
  - lib/coder_wally/user.rb
92
93
  - lib/coder_wally/version.rb
94
+ - test/account_test.rb
93
95
  - test/coder_wally_test.rb
94
96
  - test/fixtures/200.json
95
97
  - test/fixtures/404.json
@@ -121,6 +123,7 @@ signing_key:
121
123
  specification_version: 4
122
124
  summary: A simple gem to fetch user badges from Coder Wall
123
125
  test_files:
126
+ - test/account_test.rb
124
127
  - test/coder_wally_test.rb
125
128
  - test/fixtures/200.json
126
129
  - test/fixtures/404.json