snp_vk_parser 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2d96b836538cd3b9a33a496e83221288c0242ea
4
+ data.tar.gz: 19ba698b3c4ebf77795c5e443a0270e463162267
5
+ SHA512:
6
+ metadata.gz: 487fa012a0bbf7918fe071f45474306649ff958bb4c778352ccee11275daf6b2c8349630e3f1a7d8c8b9287ce8a2ec8c69e8b1e5675f45b0a99689181d7f0281
7
+ data.tar.gz: 0aad7a4a947d7bf14c0f8606542347556b237d0d42858025a71b0b99e7c5f47c58196655340ddaf8de1f2ab982d8b79c5b008cac165af86333d03446834908bf
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+ [*]
8
+
9
+ # Change these settings to your own preference
10
+ indent_style = space
11
+ indent_size = 2
12
+
13
+ # We recommend you to keep these unchanged
14
+ end_of_line = lf
15
+ charset = utf-8
16
+ trim_trailing_whitespace = true
17
+ insert_final_newline = true
18
+
19
+ [*.md]
20
+ trim_trailing_whitespace = false
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/support/cassettes/
10
+ /tmp/
11
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/**/*
4
+ - db/**/*
5
+ RunRailsCops: true
6
+ Style/Documentation:
7
+ Enabled: false
8
+ Metrics/LineLength:
9
+ Max: 120
10
+ Metrics/MethodLength:
11
+ Max: 20
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in snp_vk_parser.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ivan Novikov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # SnpVkParser
2
+
3
+ ![Salt & Pepper](https://avatars3.githubusercontent.com/u/9194399?v=3&s=100)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'snp_vk_parser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install snp_vk_parser
20
+
21
+ ## Usage
22
+
23
+
24
+ ### Group user activity
25
+
26
+ ```ruby
27
+ vk_group = SnpVkParser::Group.new(id: group_id, user_id: user_id, post_ids: post_ids, token: token)
28
+ ```
29
+
30
+ Check membership
31
+
32
+ ```ruby
33
+ vk_group.member?
34
+ ```
35
+
36
+ List ids members
37
+
38
+ ```ruby
39
+ vk_group.members
40
+ ```
41
+
42
+ #### Counters:
43
+
44
+ - In posts:
45
+
46
+ ```ruby
47
+ vk_group.posts_user_comment_count
48
+ ```
49
+
50
+ ```ruby
51
+ vk_group.posts_user_like_count
52
+ ```
53
+
54
+ ```ruby
55
+ vk_group.posts_user_repost_count
56
+ ```
57
+
58
+ - In albums:
59
+
60
+ ```ruby
61
+ vk_group.albums_user_photo_count
62
+ ```
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/groony/snp_vk_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
73
+
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
78
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'snp_vk_parser'
5
+ require 'irb'
6
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require 'snp_vk_parser/version'
2
+ require 'snp_vk_parser/group'
3
+
4
+ # Module to work with VK api.
5
+ module SnpVkParser
6
+ end
@@ -0,0 +1,110 @@
1
+ require 'vkontakte_api'
2
+
3
+ module SnpVkParser
4
+ # Class for work with group and user in group.
5
+ class Group
6
+ attr_reader :vk_client
7
+ attr_accessor :id, :user_id, :token, :post_ids, :album_ids
8
+
9
+ # Initialize.
10
+ def initialize(params = {})
11
+ params.each { |key, value| instance_variable_set("@#{key}", value) }
12
+ end
13
+
14
+ # Vk client.
15
+ def vk_client
16
+ @vk_client = VkontakteApi::Client.new token
17
+ end
18
+
19
+ # Count user comments in posts.
20
+ # @return [Integer] Ammount of comments.
21
+ def posts_user_comment_count
22
+ count = 0
23
+ posts.map do |p|
24
+ vk_client.wall.get_comments(owner_id: id, post_id: p.id).each_with_index do |comment, index|
25
+ next if index == 0
26
+ count += 1 if comment.from_id == user_id
27
+ end
28
+ end
29
+ count
30
+ end
31
+
32
+ # Count user likes in posts.
33
+ # @return [Integer] Ammount of likes.
34
+ def posts_user_like_count
35
+ count = 0
36
+ posts.map do |p|
37
+ vk_client.likes.get_list(owner_id: id, type: 'post', item_id: p.id).users.each do |u|
38
+ count += 1 if u == user_id
39
+ end
40
+ end
41
+ count
42
+ end
43
+
44
+ # Count user reposts in posts.
45
+ # @return [Integer] Ammount of reposts.
46
+ def posts_user_repost_count
47
+ count = 0
48
+ posts.map do |p|
49
+ vk_client.wall.get_reposts(owner_id: id, post_id: p.id).profiles.each do |u|
50
+ count += 1 if u.uid == user_id
51
+ end
52
+ end
53
+ count
54
+ end
55
+
56
+ # Count user photos in albums.
57
+ # @return [Integer] Ammount of photos.
58
+ def albums_user_photo_count
59
+ count = 0
60
+ albums.each do |a|
61
+ vk_client.photos.get(owner_id: a.owner_id, album_id: a.aid).each do |p|
62
+ count += 1 if p.user_id == user_id
63
+ end
64
+ end
65
+ count
66
+ end
67
+
68
+ # Check user is member.
69
+ # @return [Boolean]
70
+ def member?
71
+ vk_client.groups.is_member(group_id: id.abs, user_id: user_id) == 1
72
+ end
73
+
74
+ # Members ids.
75
+ # @return [Array] Array of user ids.
76
+ def members
77
+ vk_client.groups.get_members(group_id: id.abs).users
78
+ end
79
+
80
+ private
81
+
82
+ # Get posts.
83
+ # @return [Array] Array of posts.
84
+ def posts
85
+ if post_ids.respond_to?(:each) && post_ids.any?
86
+ posts = vk_client.wall.getById(posts: post_ids_string)
87
+ else
88
+ posts = vk_client.wall.get(owner_id: id)
89
+ posts.shift
90
+ end
91
+ posts
92
+ end
93
+
94
+ # Convert post ids to string.
95
+ # @return [String] Post ids with owner.
96
+ def post_ids_string
97
+ post_ids.map { |p| "#{id}_#{p}" }.join ','
98
+ end
99
+
100
+ # Get albums.
101
+ # @return [Array] Array of albums.
102
+ def albums
103
+ if album_ids.respond_to?(:each) && album_ids.any?
104
+ vk_client.photos.get_albums(owner_id: id, album_ids: album_ids.join(','))
105
+ else
106
+ vk_client.photos.get_albums(owner_id: id)
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,4 @@
1
+ module SnpVkParser
2
+ # Current version.
3
+ VERSION = '0.1.1'
4
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'snp_vk_parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'snp_vk_parser'
8
+ spec.version = SnpVkParser::VERSION
9
+ spec.authors = ['Ivan Novikov']
10
+ spec.email = ['ivan.novikov@saltpepper.ru']
11
+
12
+ spec.summary = 'SNP VK API allows you some awesome features'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.add_runtime_dependency 'vkontakte_api', '~> 1.4'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'vcr'
27
+ spec.add_development_dependency 'webmock'
28
+ spec.add_development_dependency 'factory_girl', '~> 4.0'
29
+ spec.add_development_dependency 'simplecov'
30
+ spec.add_development_dependency 'yard'
31
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snp_vk_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Novikov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: vkontakte_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_girl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - ivan.novikov@saltpepper.ru
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".editorconfig"
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".travis.yml"
151
+ - CODE_OF_CONDUCT.md
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - lib/snp_vk_parser.rb
159
+ - lib/snp_vk_parser/group.rb
160
+ - lib/snp_vk_parser/version.rb
161
+ - snp_vk_parser.gemspec
162
+ homepage: ''
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.4.5.1
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: SNP VK API allows you some awesome features
186
+ test_files: []
187
+ has_rdoc: