social_net 0.1.1 → 0.2.1

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +23 -0
  3. data/CHANGELOG.md +5 -1
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +20 -3
  6. data/lib/social_net/instagram/models/user.rb +15 -1
  7. data/lib/social_net/instagram/models/video.rb +17 -0
  8. data/lib/social_net/instagram/models.rb +1 -0
  9. data/lib/social_net/version.rb +1 -1
  10. data/spec/social_net/instagram/models/user_spec.rb +13 -0
  11. data/spec/support/cassettes/Posts/_posts/given_an_existing_case-insensitive_username/returns_an_object_representing_that_user.yml +48 -0
  12. data/spec/support/cassettes/Posts/_posts/given_an_unknown_username/.yml +48 -0
  13. data/spec/support/cassettes/SocialNet_Instagram_Models_User/_posts/given_an_existing_user/returns_an_array_of_posts_from_the_user.yml +883 -0
  14. metadata +9 -31
  15. data/Gemfile.lock +0 -94
  16. data/coverage/.last_run.json +0 -5
  17. data/coverage/.resultset.json +0 -847
  18. data/coverage/.resultset.json.lock +0 -0
  19. data/coverage/assets/0.9.0/application.css +0 -799
  20. data/coverage/assets/0.9.0/application.js +0 -1707
  21. data/coverage/assets/0.9.0/colorbox/border.png +0 -0
  22. data/coverage/assets/0.9.0/colorbox/controls.png +0 -0
  23. data/coverage/assets/0.9.0/colorbox/loading.gif +0 -0
  24. data/coverage/assets/0.9.0/colorbox/loading_background.png +0 -0
  25. data/coverage/assets/0.9.0/favicon_green.png +0 -0
  26. data/coverage/assets/0.9.0/favicon_red.png +0 -0
  27. data/coverage/assets/0.9.0/favicon_yellow.png +0 -0
  28. data/coverage/assets/0.9.0/loading.gif +0 -0
  29. data/coverage/assets/0.9.0/magnify.png +0 -0
  30. data/coverage/assets/0.9.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  31. data/coverage/assets/0.9.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  32. data/coverage/assets/0.9.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  33. data/coverage/assets/0.9.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  34. data/coverage/assets/0.9.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  35. data/coverage/assets/0.9.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  36. data/coverage/assets/0.9.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  37. data/coverage/assets/0.9.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  38. data/coverage/assets/0.9.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  39. data/coverage/assets/0.9.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  40. data/coverage/assets/0.9.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  41. data/coverage/assets/0.9.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  42. data/coverage/assets/0.9.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  43. data/coverage/index.html +0 -5624
  44. data/social_net-0.1.0.gem +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26881d44493639d136df86db159bcb5d40efa27f
4
- data.tar.gz: f2d57936c89e67e93d214ad47327753f644d32f3
3
+ metadata.gz: f98753cdb78bc43e646f22a215b0b2dcdb638630
4
+ data.tar.gz: bce5fe766ad93f60dc36d4657aa521c397007e3e
5
5
  SHA512:
6
- metadata.gz: 9beafaaacab822d3c1aaf277514e80ac3d88b47903dc2730c0ca1bc808663fa8c6596ab35a77a727c90639c6802178cea090977a66bbe23e527cb92fae490d4d
7
- data.tar.gz: 445b6d640dbc4a09347954b441f8d96b07d5065515643246f7d5314b958c664829539068eda8233a7ac6f99fa7ddaf0af736ea9e6fad67867149771f7140f92d
6
+ metadata.gz: f1e583a86fd6e9233169107eaa05e30a865ba148a1a2787030e6dc3a0ec5d4f86dc03221dc0a35d11cba044de0ce53ad29182b48d526088a4938175c53412e5e
7
+ data.tar.gz: d83f3ece9d7c1c546404d2f8c945e6b09c57709eca1984a9d6825b7f1ec82cd1f48716e36e46ed050254b93dde354ead27f2d7a146bdaf4acded2157fc8dab43
data/.gitignore ADDED
@@ -0,0 +1,23 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .DS_Store
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
- ## 0.1.0 - 2017-3-13
9
+ ## 0.1.1 - 2017-3-13
10
10
 
11
11
  * Initial release with `Instagram::User` supporting `find_by`, `find_by!` and `where`.
12
+
13
+ ## 0.2.1 - 2017-3-14
14
+
15
+ * [FEATURE] Add `.posts` to instance of `Instagram::User`.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2017 Collab, Inc.
1
+ Copyright 2014 Fullscreen, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -3,6 +3,7 @@ SocialNet - a Ruby client for social networks API
3
3
 
4
4
  SocialNet helps you write apps that need to interact with Twitter, Instagram and Facebook.
5
5
 
6
+ ## Note: Only Instagram works at the moment
6
7
 
7
8
  After [configuring your Twitter app](#configuring-your-twitter-app), you can run commands like:
8
9
 
@@ -17,6 +18,13 @@ After [configuring your Instagram app](#configuring-your-instagram-app), you can
17
18
  user = SocialNet::Instagram::User.find_by username: 'Collab'
18
19
  user.username #=> "Collab"
19
20
  user.follower_count #=> 7025
21
+ user.posts #=>
22
+ # [SocialNet::Instagram::Models::Video
23
+ # @caption='Diet starts Monday... 😂🍩',
24
+ # @file='https://scontent.cdninstagram.com/t50.2886-16/17192719_791273527696774_5253726776697290752_n.mp4',
25
+ # @id='1464710084172115373_487786346',
26
+ # @likes=127,
27
+ # @thumbnail='https://scontent.cdninstagram.com/t51.2885-15/e15/17076697_308353549580106_8220285822193106944_n.jpg']"
20
28
  ```
21
29
 
22
30
  After [configuring your Facebook app](#configuring-your-facebook-app), you can run commands like:
@@ -24,7 +32,7 @@ After [configuring your Facebook app](#configuring-your-facebook-app), you can r
24
32
  ```ruby
25
33
  page = SocialNet::Facebook::Page.find_by username: 'collab'
26
34
  page.username #=> "collab"
27
- page.likes #=> 30094
35
+ page.likes #=> 23289
28
36
  ```
29
37
 
30
38
  How to install
@@ -32,11 +40,11 @@ How to install
32
40
 
33
41
  To install on your system, run
34
42
 
35
- gem install net
43
+ gem install social_net
36
44
 
37
45
  To use inside a bundled Ruby project, add this line to the Gemfile:
38
46
 
39
- gem 'social_net', '~> 0.1.0'
47
+ gem 'social_net', '~> 0.1.1'
40
48
 
41
49
  Since the gem follows [Semantic Versioning](http://semver.org),
42
50
  indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
@@ -73,6 +81,7 @@ Use [SocialNet::Instagram::User]() to:
73
81
  * retrieve an Instagram user by username
74
82
  * retrieve an Instagram user by id
75
83
  * access the number of followers of an Instagram user
84
+ * retrieve recent posts of an Instagram user
76
85
 
77
86
  ```ruby
78
87
  user = SocialNet::Instagram::User.find_by username: 'collab'
@@ -80,6 +89,14 @@ user.follower_count #=> 24198
80
89
 
81
90
  user = SocialNet::Instagram::User.find_by id: 270587948
82
91
  user.follower_count #=> 24198
92
+
93
+ user.posts #=>
94
+ # [SocialNet::Instagram::Models::Video
95
+ # @caption='Diet starts Monday... 😂🍩',
96
+ # @file='https://scontent.cdninstagram.com/t50.2886-16/17192719_791273527696774_5253726776697290752_n.mp4',
97
+ # @id='1464710084172115373_487786346',
98
+ # @likes=127,
99
+ # @thumbnail='https://scontent.cdninstagram.com/t51.2885-15/e15/17076697_308353549580106_8220285822193106944_n.jpg']"
83
100
  ```
84
101
 
85
102
  *The methods above require a configured Instagram app (see below).*
@@ -5,13 +5,27 @@ module SocialNet
5
5
  module Instagram
6
6
  module Models
7
7
  class User
8
- attr_reader :username, :follower_count
8
+ attr_reader :id, :username, :follower_count
9
9
 
10
10
  def initialize(attrs = {})
11
+ @id = attrs['id']
11
12
  @username = attrs['username']
12
13
  @follower_count = attrs['counts']['followed_by']
13
14
  end
14
15
 
16
+ # Returns the existing Instagram user's posts
17
+ #
18
+ # @return [SocialNet::Instagram::Models::Video] when the posts are found.
19
+ def posts
20
+ request = Api::Request.new endpoint: "users/#{id}/media/recent"
21
+ videos = request.run.select {|p| p['type'] == 'video'}
22
+ videos.map {|r| SocialNet::Instagram::Video.new r }
23
+ rescue Errors::ResponseError => error
24
+ case error.response
25
+ when Net::HTTPBadRequest then raise Errors::UnknownUser
26
+ end
27
+ end
28
+
15
29
  # Returns the existing Instagram user matching the provided attributes or
16
30
  # nil when the user is not found.
17
31
  #
@@ -0,0 +1,17 @@
1
+ module SocialNet
2
+ module Instagram
3
+ module Models
4
+ class Video
5
+ attr_reader :id, :caption, :likes, :file, :thumbnail
6
+
7
+ def initialize(attrs = {})
8
+ @id = attrs['id']
9
+ @caption = attrs['caption']['text']
10
+ @likes = attrs['likes']['count']
11
+ @file = attrs['videos']['standard_resolution']['url']
12
+ @thumbnail = attrs['images']['standard_resolution']['url']
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1 +1,2 @@
1
1
  require 'social_net/instagram/models/user'
2
+ require 'social_net/instagram/models/video'
@@ -1,3 +1,3 @@
1
1
  module SocialNet
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -37,6 +37,7 @@ describe SocialNet::Instagram::User, :vcr do
37
37
  let(:username) { existing_username }
38
38
 
39
39
  it 'returns an object representing that user' do
40
+
40
41
  expect(user.username).to eq 'collab'
41
42
  expect(user.follower_count).to be_an Integer
42
43
  end
@@ -47,4 +48,16 @@ describe SocialNet::Instagram::User, :vcr do
47
48
  it { expect{user}.to raise_error SocialNet::Instagram::UnknownUser }
48
49
  end
49
50
  end
51
+
52
+ describe '.posts' do
53
+ subject(:user) { SocialNet::Instagram::User.find_by! username: username }
54
+ context 'given an existing user' do
55
+ let(:username) { existing_username }
56
+
57
+ it 'returns an array of posts from the user' do
58
+ expect(user.posts).to be_an Array
59
+ expect(user.posts.first).to be_an_instance_of SocialNet::Instagram::Video
60
+ end
61
+ end
62
+ end
50
63
  end
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.instagram.com/v1/users/search?access_token=INSTAGRAM_ACCESS_TOKEN&q=Collab
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 400
19
+ message: Bad Request
20
+ headers:
21
+ Expires:
22
+ - Sat, 01 Jan 2000 00:00:00 GMT
23
+ Cache-Control:
24
+ - private, no-cache, no-store, must-revalidate
25
+ Date:
26
+ - Tue, 14 Mar 2017 18:30:53 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Vary:
30
+ - Cookie, Accept-Language
31
+ Pragma:
32
+ - no-cache
33
+ Content-Language:
34
+ - en
35
+ Set-Cookie:
36
+ - csrftoken=qm9rhW3Ww7Yj6slrRPYWIrsnuh2w7DXs; expires=Tue, 13-Mar-2018 18:30:53
37
+ GMT; Max-Age=31449600; Path=/; Secure
38
+ Connection:
39
+ - keep-alive
40
+ Content-Length:
41
+ - '124'
42
+ body:
43
+ encoding: UTF-8
44
+ string: '{"meta": {"error_type": "OAuthAccessTokenException", "error_message":
45
+ "The access_token provided is invalid.", "code": 400}}'
46
+ http_version:
47
+ recorded_at: Tue, 14 Mar 2017 18:30:53 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.instagram.com/v1/users/search?access_token=INSTAGRAM_ACCESS_TOKEN&q=01LjqweoojkjR
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 400
19
+ message: Bad Request
20
+ headers:
21
+ Pragma:
22
+ - no-cache
23
+ Date:
24
+ - Tue, 14 Mar 2017 18:30:53 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Vary:
28
+ - Cookie, Accept-Language
29
+ Expires:
30
+ - Sat, 01 Jan 2000 00:00:00 GMT
31
+ Cache-Control:
32
+ - private, no-cache, no-store, must-revalidate
33
+ Content-Language:
34
+ - en
35
+ Set-Cookie:
36
+ - csrftoken=bOYUC9lDOgvLXo3ihcbQ3YMASKPOVTWS; expires=Tue, 13-Mar-2018 18:30:53
37
+ GMT; Max-Age=31449600; Path=/; Secure
38
+ Connection:
39
+ - keep-alive
40
+ Content-Length:
41
+ - '124'
42
+ body:
43
+ encoding: UTF-8
44
+ string: '{"meta": {"code": 400, "error_message": "The access_token provided
45
+ is invalid.", "error_type": "OAuthAccessTokenException"}}'
46
+ http_version:
47
+ recorded_at: Tue, 14 Mar 2017 18:30:53 GMT
48
+ recorded_with: VCR 2.9.3