fb_graph2 0.7.1 → 0.7.2

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: 03da19a78687fcaebeb137d42c3c670170905aa2
4
- data.tar.gz: 427b1e1af1e76e63a71126cedd65e4de011e05af
3
+ metadata.gz: 47cc32a9ad029bbad0346803bf8ca999ae2b3d75
4
+ data.tar.gz: eaef411ebb5075c1ca0bc616ed597e2d6fdfa2de
5
5
  SHA512:
6
- metadata.gz: 205004ed8089e449a4bbe83e439b79446bd9024db08ce8b36ebc1350b237e80b1bfcedff446ac0a64d76e869745cbb80db4339bc1bf390e192f02e361230478e
7
- data.tar.gz: dc48a4d342b3f3dfbcfa76d1f229454857781890dc529cf1956b5b10dc0183f3fe4e3ea671c89ce1319e03a7d83bd038d8da0d8ec6cca298011afba9e4f5cf4f
6
+ metadata.gz: b610f4cce39977ed93d62187ae635759ed5a7c2e7dd62f718792f41af5a91d8f7531a5494478c402679e2e02484daddc29da634b7295d16d9a746fe738c5fc43
7
+ data.tar.gz: e5c23365053ba2cbca1814042680a7d17db74793bad2da1fc8911eef04cc6e393f522ecbdca7e0eee8f8462f9a11338a32a40f05f6c484f99a35389fb01352da
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.2
@@ -8,26 +8,28 @@ module FbGraph2
8
8
  end
9
9
 
10
10
  module ClassMethods
11
- def register_attributes(attributes)
12
- @registered_attributes ||= {}
13
- attributes.each do |type, keys|
14
- @registered_attributes[type] ||= []
15
- @registered_attributes[type] += keys
16
- end
17
- send :attr_accessor, *attributes.values.flatten
11
+ attr_reader :registered_attributes
12
+
13
+ def inherited(child)
14
+ super
15
+ child.register_attributes registered_attributes
18
16
  end
19
17
 
20
18
  def registered_attributes
21
- @registered_attributes
19
+ @registered_attributes ||= {}
22
20
  end
23
21
 
24
- def inherited(child)
25
- super
26
- child.register_attributes registered_attributes
22
+ def register_attributes(attributes)
23
+ attributes.each do |type, keys|
24
+ registered_attributes[type] ||= []
25
+ registered_attributes[type] += keys
26
+ end
27
+ send :attr_accessor, *attributes.values.flatten
27
28
  end
28
29
  end
29
30
 
30
31
  def assign(attributes)
32
+ self.raw_attributes = attributes
31
33
  Array(self.class.registered_attributes).each do |type, keys|
32
34
  keys.each do |key|
33
35
  if attributes.include? key
@@ -91,9 +93,11 @@ module FbGraph2
91
93
  Collection.new(raw).collect! do |_raw_|
92
94
  Struct::Tag.new _raw_
93
95
  end
94
- else
96
+ when :custom
95
97
  # NOTE: handle these attributes in each class
96
98
  next
99
+ else
100
+ raise "unknown attribute type #{type}"
97
101
  end
98
102
  self.send :"#{key}=", value
99
103
  end
@@ -1,17 +1,12 @@
1
1
  module FbGraph2
2
2
  class Node
3
- attr_accessor :id, :access_token, :raw_attributes
3
+ include AttributeAssigner
4
+ attr_accessor :id, :access_token
4
5
  alias_method :identifier, :id
5
6
 
6
- def self.inherited(klass)
7
- klass.send :include, AttributeAssigner
8
- FbGraph2.object_classes << klass
9
- end
10
-
11
7
  def initialize(id, attributes = {})
12
8
  self.id = id
13
- self.raw_attributes = attributes
14
- assign attributes if respond_to? :assign
9
+ assign attributes
15
10
  authenticate attributes[:access_token] if attributes.include? :access_token
16
11
  end
17
12
 
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  class Rating < Struct
4
4
  register_attributes(
5
5
  raw: [:has_rating, :has_review, :rating, :review_text],
6
- datetime: [:created_time],
6
+ time: [:created_time],
7
7
  user: [:reviewer],
8
8
  custom: [:open_graph_story]
9
9
  )
@@ -1,11 +1,9 @@
1
1
  module FbGraph2
2
2
  class Struct
3
- def self.inherited(klass)
4
- klass.send :include, AttributeAssigner
5
- end
3
+ include AttributeAssigner
6
4
 
7
5
  def initialize(attributes = {})
8
- assign attributes if respond_to? :assign
6
+ assign attributes
9
7
  end
10
8
  end
11
9
  end
data/lib/fb_graph2.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext'
3
+ require 'active_support/concern'
3
4
  require 'rack/oauth2'
4
5
 
5
6
  module FbGraph2
@@ -10,9 +11,12 @@ module FbGraph2
10
11
  self.gem_version = File.read(File.join(__dir__, '../VERSION')).strip
11
12
  self.logger = Logger.new(STDOUT)
12
13
  self.logger.progname = 'FbGraph2'
13
- self.object_classes = Array.new
14
14
 
15
15
  class << self
16
+ def object_classes
17
+ FbGraph2::Node.descendants
18
+ end
19
+
16
20
  def debugging?
17
21
  !!self.debugging
18
22
  end
@@ -2,21 +2,19 @@ require 'spec_helper'
2
2
 
3
3
  describe FbGraph2::App do
4
4
  describe '.app' do
5
- let(:klass) { FbGraph2::App }
6
-
7
5
  it 'should not call API' do
8
6
  expect do
9
- app = klass.app 'token'
10
- app.should be_instance_of klass
7
+ app = described_class.app 'token'
8
+ app.should be_instance_of described_class
11
9
  end.not_to request_to 'app'
12
10
  end
13
11
 
14
12
  context 'when fetched' do
15
13
  it 'should call API' do
16
14
  app = mock_graph :get, 'app', 'app/app' do
17
- klass.app('token').fetch
15
+ described_class.app('token').fetch
18
16
  end
19
- app.should be_instance_of klass
17
+ app.should be_instance_of described_class
20
18
  end
21
19
  end
22
20
  end
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FbGraph2::Node do
4
- let(:klass) { FbGraph2::Node }
5
- let(:instance) { klass.new 'identifier' }
4
+ let(:instance) { described_class.new 'identifier' }
6
5
 
7
6
  describe 'API Versioning' do
8
7
  before do
@@ -56,15 +55,8 @@ describe FbGraph2::Node do
56
55
  end
57
56
  end
58
57
 
59
- context 'class' do
60
- subject { klass }
61
- it { should_not respond_to :register_attributes }
62
- it { should_not respond_to :registered_attributes }
63
- end
64
-
65
58
  context 'instance' do
66
59
  subject { instance }
67
- it { should_not respond_to :assign }
68
60
 
69
61
  describe '#initialize' do
70
62
  its(:id) { should == 'identifier' }
@@ -6,17 +6,7 @@ module FbGraph2
6
6
  end
7
7
 
8
8
  describe FbGraph2::NodeSubClass do
9
- let(:klass) { FbGraph2::NodeSubClass }
10
- let(:instance) { klass.new 'identifier' }
11
-
12
- context 'class' do
13
- subject { klass }
14
- it { should respond_to :register_attributes }
15
- it { should respond_to :registered_attributes }
16
- end
17
-
18
- context 'instance' do
19
- subject { instance }
20
- it { should respond_to :assign }
9
+ it 'should be included in FbGraph2.object_classes' do
10
+ FbGraph2.object_classes.should include described_class
21
11
  end
22
12
  end
@@ -1,11 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FbGraph2::RequestFilter::Authenticator do
4
- let(:klass) { FbGraph2::RequestFilter::Authenticator }
5
-
6
4
  let(:endpoint) { 'https://graph.facebook.com/matake' }
7
5
  let(:request) { HTTP::Message.new_request(:get, URI.parse(endpoint)) }
8
- let(:request_filter) { klass.new token }
6
+ let(:request_filter) { described_class.new token }
9
7
 
10
8
  context 'when String given' do
11
9
  let(:token) { 'token' }
@@ -2,27 +2,25 @@ require 'spec_helper'
2
2
 
3
3
  describe FbGraph2::User do
4
4
  describe '.me' do
5
- let(:klass) { FbGraph2::User }
6
-
7
5
  it 'should not call API' do
8
6
  expect do
9
- me = klass.me 'token'
10
- me.should be_instance_of klass
7
+ me = described_class.me 'token'
8
+ me.should be_instance_of described_class
11
9
  end.not_to request_to 'me'
12
10
  end
13
11
 
14
12
  context 'when fetched' do
15
13
  it 'should call API' do
16
14
  me = mock_graph :get, 'me', 'user/me' do
17
- klass.me('token').fetch
15
+ described_class.me('token').fetch
18
16
  end
19
- me.should be_instance_of klass
17
+ me.should be_instance_of described_class
20
18
  end
21
19
 
22
20
  context 'when ext attrs included' do
23
21
  it 'should success to parse' do
24
22
  me = mock_graph :get, 'me', 'user/me_with_ext_attrs' do
25
- klass.me('token').fetch
23
+ described_class.me('token').fetch
26
24
  end
27
25
  [
28
26
  :age_range, :context, :currency, :devices
@@ -8,7 +8,6 @@ describe FbGraph2 do
8
8
  its(:logger) { should be_a Logger }
9
9
  its(:api_version) { should == 'v2.3' }
10
10
  its(:root_url) { should == 'https://graph.facebook.com' }
11
- its(:object_classes) { should contain_exactly *FbGraph2::Node.subclasses + [FbGraph2::Place] }
12
11
  it { should_not be_debugging }
13
12
  end
14
13
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-07 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient