ig_api 0.0.9 → 0.0.10

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
  SHA256:
3
- metadata.gz: fc8cf14005561039a3e6360eb2b424c288ac9326aeaa66d4ca3076ac5209c820
4
- data.tar.gz: a8b446caf588d41ae4ddcd6f654d7f4598675dbe5f09fb28a573c59987a07dff
3
+ metadata.gz: f3c4a1db764e7e898ea324eefc4c6afdef93a4977c01ee2b9c21cbb91e06975d
4
+ data.tar.gz: e1534f868ed4577c8cee8fae08c745bd50b476de20a346223cb28f054ca6a281
5
5
  SHA512:
6
- metadata.gz: 45ab88b0becd54ef5a18299ee7dce50810574c8c5b232771399fe09467b162955cb6c0a7a8fcff3febb394823c2b738f85aafae1a6ed4b1c5a22efd9418b8f32
7
- data.tar.gz: 9e72c2327dd300c5654074019a892a7aa3d3600ecbf47deaeeab3787c718b14ef4f1339e5dba86534c2d48a43ef7d47ff75d7afa4baf9a25ca707421c45d08c4
6
+ metadata.gz: c718581e3838ab83822efa3e7122cdb1ab7b387cd751f95c5cc028c98ab62580912cd49d701edc6982aea049e667087c0ddfabeea33760ea3124f435461d2360
7
+ data.tar.gz: 8884afcf7a1fbd2ea1ef4e16a698649a10330ac4def85627aa28e0f480ca7287b5711d17fca658a2cdb366445f96a5309f4b61a2f8c027a781707881bf900122
data/Gemfile.lock CHANGED
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ig_api (0.0.8)
4
+ ig_api (0.0.10)
5
+ rspec (~> 3.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  diff-lcs (1.3)
11
+ multipart-post (2.0.0)
10
12
  rake (10.5.0)
11
13
  rspec (3.7.0)
12
14
  rspec-core (~> 3.7.0)
@@ -29,8 +31,8 @@ PLATFORMS
29
31
  DEPENDENCIES
30
32
  bundler (~> 1.16)
31
33
  ig_api!
34
+ multipart-post (~> 2.0.0)
32
35
  rake (~> 10.0)
33
- rspec (~> 3.0)
34
36
 
35
37
  BUNDLED WITH
36
38
  1.16.2
data/README.md CHANGED
@@ -25,8 +25,6 @@ user.relationship.create search.id #follow
25
25
  ```
26
26
  - Rails
27
27
  ```ruby
28
- require 'IgApi'
29
-
30
28
  class HomeController < ApplicationController
31
29
  def index
32
30
  account = IgApi::Account.new
data/ig_api.gemspec CHANGED
@@ -31,6 +31,8 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ['lib']
32
32
 
33
33
  spec.add_development_dependency 'bundler', '~> 1.16'
34
+ spec.add_development_dependency 'multipart-post', '~> 2.0.0'
34
35
  spec.add_development_dependency 'rake', '~> 10.0'
35
- spec.add_development_dependency 'rspec', '~> 3.0'
36
+
37
+ spec.add_dependency 'rspec', '~> 3.0'
36
38
  end
@@ -10,8 +10,21 @@ module IgApi
10
10
  @api
11
11
  end
12
12
 
13
+ def using(session)
14
+ user = User.new session: session
15
+
16
+ # response = api.get(Constants::URL + 'accounts/current_user/?edit=true')
17
+ # .with(ua: user.useragent, session: user.session).exec
18
+ #
19
+ # response.body
20
+ #
21
+
22
+ user
23
+ end
24
+
13
25
  def login(username, password, config = IgApi::Configuration.new)
14
- user = User.new username, password
26
+ user = User.new username: username,
27
+ password: password
15
28
 
16
29
  request = api.post(
17
30
  Constants::URL + 'accounts/login/',
@@ -84,7 +97,7 @@ module IgApi
84
97
  json_result = JSON.parse result.body
85
98
  if json_result['num_results'] > 0
86
99
  user_result = json_result['users'][0]
87
- user_object = IgApi::User.new username, nil
100
+ user_object = IgApi::User.new username: username
88
101
  user_object.data = {
89
102
  id: user_result['pk'],
90
103
  full_name: user_result['full_name'],
data/lib/ig_api/feed.rb CHANGED
@@ -6,9 +6,9 @@ module IgApi
6
6
 
7
7
  def using user
8
8
  @user = {
9
- id: user.data[:id],
10
- session: user.session,
11
- ua: user.useragent
9
+ id: user.data[:id],
10
+ session: user.session,
11
+ ua: user.useragent
12
12
  }
13
13
  self
14
14
  end
@@ -18,9 +18,8 @@ module IgApi
18
18
 
19
19
  rank_token = IgApi::Http.generate_rank_token @user[:id]
20
20
  endpoint = "https://i.instagram.com/api/v1/feed/user/#{user_id}/"
21
- param = "?rank_token=#{rank_token}"
22
- result = @api.get(endpoint + param)
23
- .with(session: @user[:session], ua: @user[:ua]).exec
21
+ result = @api.get(endpoint + "?rank_token=#{rank_token}")
22
+ .with(session: @user[:session], ua: @user[:ua]).exec
24
23
 
25
24
  JSON.parse result.body
26
25
  end
data/lib/ig_api/http.rb CHANGED
@@ -8,6 +8,7 @@ require 'ig_api/user'
8
8
  require 'ig_api/account'
9
9
  require 'ig_api/feed'
10
10
  require 'ig_api/configuration'
11
+ require 'net/http/post/multipart'
11
12
 
12
13
  module IgApi
13
14
  class Http
@@ -56,6 +57,11 @@ module IgApi
56
57
  self
57
58
  end
58
59
 
60
+ def multipart(url, body = nil)
61
+ @data = { method: 'MULTIPART', url: url, body: body }
62
+ self
63
+ end
64
+
59
65
  def with(data)
60
66
  data.each { |k, v| @data[k] = v }
61
67
  self
@@ -81,16 +87,29 @@ module IgApi
81
87
  request = Net::HTTP::Post.new(args[:url].path)
82
88
  elsif args[:method] == 'GET'
83
89
  request = Net::HTTP::Get.new(args[:url].path + (!args[:url].nil? ? '?' + args[:url].query : ''))
90
+ elsif args[:method] == 'MULTIPART'
91
+ request = Net::HTTP::Post::Multipart.new args[:url].path, args[:body],
92
+ 'User-Agent': args[:ua],
93
+ Accept: IgApi::Constants::HEADER[:accept],
94
+ 'Accept-Encoding': IgApi::Constants::HEADER[:encoding],
95
+ 'Accept-Language': 'en-US',
96
+ 'X-IG-Capabilities': IgApi::Constants::HEADER[:capabilities],
97
+ 'X-IG-Connection-Type': IgApi::Constants::HEADER[:type],
98
+ Cookie: args[:session] || ''
99
+ end
100
+
101
+ unless args[:method] == 'MULTIPART'
102
+ request.initialize_http_header('User-Agent': args[:ua],
103
+ Accept: IgApi::Constants::HEADER[:accept],
104
+ 'Accept-Encoding': IgApi::Constants::HEADER[:encoding],
105
+ 'Accept-Language': 'en-US',
106
+ 'X-IG-Capabilities': IgApi::Constants::HEADER[:capabilities],
107
+ 'X-IG-Connection-Type': IgApi::Constants::HEADER[:type],
108
+ Cookie: args[:session] || '')
109
+
110
+ request.body = args.key?(:body) ? args[:body] : nil
84
111
  end
85
112
 
86
- request.initialize_http_header('User-Agent': args[:ua],
87
- Accept: IgApi::Constants::HEADER[:accept],
88
- 'Accept-Encoding': IgApi::Constants::HEADER[:encoding],
89
- 'Accept-Language': 'en-US',
90
- 'X-IG-Capabilities': IgApi::Constants::HEADER[:capabilities],
91
- 'X-IG-Connection-Type': IgApi::Constants::HEADER[:type],
92
- Cookie: args[:session] || '')
93
- request.body = args.key?(:body) ? args[:body] : nil
94
113
  http.request(request)
95
114
  end
96
115
 
@@ -0,0 +1,31 @@
1
+ module IgApi
2
+ class Thread
3
+ def initialize
4
+ @api = Http.singleton
5
+ end
6
+
7
+ def using(user)
8
+ @user = {
9
+ session: user.session,
10
+ ua: user.useragent
11
+ }
12
+
13
+ self
14
+ end
15
+
16
+ def configure_text(users, text)
17
+ body = {
18
+ recipient_users: [users].to_json,
19
+ client_context: Http.generate_uuid,
20
+ text: text
21
+ }
22
+
23
+ response = @api.multipart(Constants::URL + 'direct_v2/threads/broadcast/text/',
24
+ body)
25
+ .with(ua: @user[:ua], session: @user[:session])
26
+ .exec
27
+
28
+ response.body
29
+ end
30
+ end
31
+ end
data/lib/ig_api/user.rb CHANGED
@@ -3,25 +3,22 @@ require 'ig_api/constants'
3
3
 
4
4
  module IgApi
5
5
  class User
6
- attr_reader :username
7
- attr_reader :password
8
- attr_reader :language
9
- attr_reader :data
10
- attr_writer :data
11
- attr_reader :session
12
- attr_writer :session
13
- attr_reader :config
14
- attr_writer :config
15
-
16
- def initialize(username, password, session = nil, data = nil, config = nil)
17
- @username = username
18
- @password = password
19
- @language = 'en_US'
20
- @session = session
21
- @data = data
22
- @config = config
6
+ attr_reader :password, :language
7
+ attr_accessor :config, :session, :data
8
+
9
+ def initialize(params = {})
23
10
  @account = nil
24
11
  @feed = nil
12
+
13
+ if params.key? :session
14
+ @username = params[:session].scan(/ds_user=(.*?);/)[0][0]
15
+ end
16
+
17
+ inject_variables(params)
18
+ end
19
+
20
+ def inject_variables(params)
21
+ params.each { |key, value| instance_variable_set(:"@#{key}", value) }
25
22
  end
26
23
 
27
24
  def search_for_user(username)
@@ -60,6 +57,12 @@ module IgApi
60
57
  @feed.using(self)
61
58
  end
62
59
 
60
+ def thread
61
+ @thread = IgApi::Thread.new unless defined? @thread
62
+
63
+ @thread.using self
64
+ end
65
+
63
66
  def md5
64
67
  Digest::MD5.hexdigest @username
65
68
  end
@@ -1,3 +1,3 @@
1
1
  module IgApi
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/ig_api.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ig_api/http'
4
- require 'ig_api/constants'
5
- require 'ig_api/device'
6
4
  require 'ig_api/user'
5
+ require 'ig_api/device'
6
+ require 'ig_api/thread'
7
+ require 'ig_api/constants'
7
8
  require 'ig_api/relationship'
8
9
 
9
10
  # Root module
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ig_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - vicoerv
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-24 00:00:00.000000000 Z
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multipart-post
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +59,7 @@ dependencies:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
61
  version: '3.0'
48
- type: :development
62
+ type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
@@ -80,6 +94,7 @@ files:
80
94
  - lib/ig_api/feed.rb
81
95
  - lib/ig_api/http.rb
82
96
  - lib/ig_api/relationship.rb
97
+ - lib/ig_api/thread.rb
83
98
  - lib/ig_api/user.rb
84
99
  - lib/ig_api/version.rb
85
100
  homepage: http://www.vicoervanda.com