instagrammer 0.1.3 → 0.2.0
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 +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +8 -0
- data/Guardfile +1 -1
- data/instagrammer.gemspec +1 -1
- data/lib/instagrammer.rb +2 -0
- data/lib/instagrammer/post.rb +31 -19
- data/lib/instagrammer/user.rb +3 -13
- data/lib/instagrammer/utils.rb +15 -0
- data/lib/instagrammer/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3a1ab2d4f1152a6bf11cdb8b1b6056feeeb0dad5947d57ca20892b0c70b2756
|
4
|
+
data.tar.gz: 9fbcd09a13b62e6b35610a115a3bf156b5811abf85cf2c6651973e848808c3f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43be16412153206a20a053232c664f26607c71beb84b50cd57e8214961f6bfa24ffd426929665311ad967ce1a10f33fcd6983bf09e494957f4d95b264f3763de
|
7
|
+
data.tar.gz: b72aec029920c4e24794ce657fd3b1900557bfcde326791b59adac3adb34124738e17d3fafc5d6ec3dcf44b867ddf7e67d0752f07251245f84383a0bd160ace7
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.2.0] - 2019-07-14
|
10
|
+
### Changed
|
11
|
+
- Refactor page status internals
|
12
|
+
- Lazy load post attributes
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
- Check page status before accessing data (closes [#2](https://github.com/richardvenneman/instagrammer/issues/2))
|
16
|
+
|
9
17
|
## [0.1.3] - 2019-06-20
|
10
18
|
### Changed
|
11
19
|
- Setup test coverage
|
data/Guardfile
CHANGED
data/instagrammer.gemspec
CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency "guard", "~> 2.15"
|
35
35
|
spec.add_development_dependency "guard-minitest", "~> 2.4"
|
36
36
|
spec.add_development_dependency "minitest", "~> 5.0"
|
37
|
-
spec.add_development_dependency "rake", "~>
|
37
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
38
38
|
spec.add_development_dependency "rubocop-rails_config", "~> 0.6"
|
39
39
|
spec.add_development_dependency "simplecov", "~> 0.16"
|
40
40
|
end
|
data/lib/instagrammer.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "instagrammer/version"
|
4
|
+
require "instagrammer/utils"
|
4
5
|
require "instagrammer/config/capybara"
|
5
6
|
require "instagrammer/post"
|
6
7
|
require "instagrammer/user"
|
@@ -11,6 +12,7 @@ module Instagrammer
|
|
11
12
|
class UserNotFound < StandardError; end
|
12
13
|
|
13
14
|
class PrivatePost < StandardError; end
|
15
|
+
class PostInvalid < StandardError; end
|
14
16
|
class PostNotFound < StandardError; end
|
15
17
|
|
16
18
|
def self.new(username)
|
data/lib/instagrammer/post.rb
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
class Instagrammer::Post
|
4
4
|
include Capybara::DSL
|
5
|
+
include Instagrammer::Utils
|
5
6
|
|
6
7
|
attr_reader :shortcode, :image_url, :image_urls
|
7
8
|
|
8
9
|
def initialize(shortcode)
|
9
10
|
@shortcode = shortcode
|
10
|
-
|
11
|
+
@data = nil
|
11
12
|
end
|
12
13
|
|
13
14
|
def inspect
|
@@ -17,8 +18,24 @@ class Instagrammer::Post
|
|
17
18
|
"#<#{self.class.name}:#{object_id} #{attributes.map { |attr| "#{attr}:#{send(attr).inspect}" }.join(", ")}>"
|
18
19
|
end
|
19
20
|
|
21
|
+
def public?
|
22
|
+
get_data unless @data
|
23
|
+
@status == :public
|
24
|
+
end
|
25
|
+
|
26
|
+
def data
|
27
|
+
get_data unless @data
|
28
|
+
|
29
|
+
case @status
|
30
|
+
when :private then raise Instagrammer::PrivatePost.new("Private post: #{@shortcode}")
|
31
|
+
when :not_found then raise Instagrammer::PostNotFound.new("Post not found: #{@shortcode}")
|
32
|
+
when :invalid then raise Instagrammer::PostInvalid.new("Post invalid: #{@shortcode}")
|
33
|
+
else @data
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
20
37
|
def type
|
21
|
-
|
38
|
+
data["@type"] == "ImageObject" ? :photo : :video
|
22
39
|
end
|
23
40
|
|
24
41
|
def photo?
|
@@ -30,43 +47,38 @@ class Instagrammer::Post
|
|
30
47
|
end
|
31
48
|
|
32
49
|
def user
|
33
|
-
Instagrammer::User.new
|
50
|
+
Instagrammer::User.new data["author"]["alternateName"]
|
34
51
|
end
|
35
52
|
|
36
53
|
def caption
|
37
|
-
|
54
|
+
data["caption"]
|
38
55
|
end
|
39
56
|
|
40
57
|
def upload_date
|
41
|
-
DateTime.parse
|
58
|
+
DateTime.parse data["uploadDate"]
|
42
59
|
end
|
43
60
|
|
44
61
|
def comment_count
|
45
|
-
|
62
|
+
data["commentCount"].to_i
|
46
63
|
end
|
47
64
|
|
48
65
|
def like_count
|
49
|
-
|
66
|
+
data["interactionStatistic"]["userInteractionCount"].to_i if photo?
|
50
67
|
end
|
51
68
|
|
52
69
|
def watch_count
|
53
|
-
|
70
|
+
data["interactionStatistic"]["userInteractionCount"].to_i if video?
|
54
71
|
end
|
55
72
|
|
56
73
|
private
|
57
|
-
def
|
74
|
+
def get_data
|
58
75
|
visit "https://www.instagram.com/p/#{@shortcode}/"
|
59
|
-
|
60
|
-
|
61
|
-
@data = JSON.parse(page.first(:json_ld, visible: false).text(:all))
|
62
|
-
set_image_attributes if photo?
|
63
|
-
end
|
76
|
+
@status = get_page_status
|
64
77
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
raise Instagrammer::PostNotFound.new("Post not found: #{@shortcode}")
|
78
|
+
if @status == :public
|
79
|
+
node = page.first(:json_ld, visible: false)
|
80
|
+
@data = JSON.parse(node.text(:all))
|
81
|
+
set_image_attributes if photo?
|
70
82
|
end
|
71
83
|
end
|
72
84
|
|
data/lib/instagrammer/user.rb
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
class Instagrammer::User
|
4
4
|
include Capybara::DSL
|
5
|
+
include Instagrammer::Utils
|
5
6
|
|
6
7
|
attr_reader :posts
|
7
8
|
|
8
9
|
def initialize(username)
|
9
10
|
@username = username.delete_prefix("@")
|
11
|
+
@data = nil
|
10
12
|
@posts = []
|
11
13
|
end
|
12
14
|
|
@@ -98,7 +100,7 @@ class Instagrammer::User
|
|
98
100
|
private
|
99
101
|
def get_data
|
100
102
|
visit "https://www.instagram.com/#{@username}/"
|
101
|
-
@status =
|
103
|
+
@status = get_page_status
|
102
104
|
@meta = get_metadata unless @status == :not_found
|
103
105
|
|
104
106
|
if @status == :public
|
@@ -111,16 +113,4 @@ class Instagrammer::User
|
|
111
113
|
def get_metadata
|
112
114
|
@meta = page.first(:meta_description, visible: false)["content"].match META_RE
|
113
115
|
end
|
114
|
-
|
115
|
-
def get_account_status
|
116
|
-
if page.has_content?("Private")
|
117
|
-
:private
|
118
|
-
elsif page.has_content?("Sorry")
|
119
|
-
:not_found
|
120
|
-
elsif page.find(:json_ld, visible: false)
|
121
|
-
:public
|
122
|
-
end
|
123
|
-
rescue Capybara::ElementNotFound
|
124
|
-
:invalid
|
125
|
-
end
|
126
116
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Instagrammer::Utils
|
4
|
+
def get_page_status
|
5
|
+
if page.has_content?("Private")
|
6
|
+
:private
|
7
|
+
elsif page.has_content?("Sorry")
|
8
|
+
:not_found
|
9
|
+
elsif page.find(:json_ld, visible: false)
|
10
|
+
:public
|
11
|
+
end
|
12
|
+
rescue Capybara::ElementNotFound
|
13
|
+
:invalid
|
14
|
+
end
|
15
|
+
end
|
data/lib/instagrammer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instagrammer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Venneman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '12.3'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '12.3'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rubocop-rails_config
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/instagrammer/config/capybara.rb
|
160
160
|
- lib/instagrammer/post.rb
|
161
161
|
- lib/instagrammer/user.rb
|
162
|
+
- lib/instagrammer/utils.rb
|
162
163
|
- lib/instagrammer/version.rb
|
163
164
|
homepage: https://github.com/richardvenneman/instagrammer
|
164
165
|
licenses:
|