tinder_client 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fba975cd89b6d6717fc1b1e17992ddf0d935414a3b0215ba3583123c3aba5fc3
4
- data.tar.gz: a976afc89ffc456d642df25b630c8404df3cd6fbc3d3dc8cc64bf1025fc9f0f0
3
+ metadata.gz: 6f4ad83b15d2db91d476b1a6f0394c98bf7b2d68fbbc8283baad68ce745c454e
4
+ data.tar.gz: f8971a6dea4c42121a5156bc2284fc4e6a94a41f45aa8e98843f8cdd1b26d11d
5
5
  SHA512:
6
- metadata.gz: fe8658fa7d77e39475acd505359d1f50f2a48ff7d15f0bf8d3353861b46c9a43d88ed60553eb41f475ca083540b969ff7cd3b0f5eaa484a4fc3b9797beef914c
7
- data.tar.gz: 2881230a82f4d94fa6a62bac0ce8855796d629291cf2efff3e751e3d50d4f0431698e8c658381e9d01007e8adc8f49d820fa075423005a52d0f38311ee646fd5
6
+ metadata.gz: 80fafc81e80807001dc8ce11d9cb8cd650732cac861b66a1db4c6e06d082ddf29acd38e07011353724f4b1b14285b6f0a9bf6d421034580158f292c174976442
7
+ data.tar.gz: 44393d3dfd9d19254963015fa3a225b51f3debbcea2f9ae88e7739e4cd9b2efa5ecc1b3919d69ae40547b0cdc7d3783dce20a7078b864a8aa8dfc75ef5e75ba2
data/README.md CHANGED
@@ -51,3 +51,146 @@ RSpec.describe 'some test' do
51
51
  # Your tests that use Tinder HTTP requests go here
52
52
  end
53
53
  ```
54
+
55
+ ## Accessing your saved data
56
+
57
+ `better_tinder` converts responses from Tinder from raw JSON data to `Dry::Struct`, for your convenience.
58
+
59
+ That means, call the services with your API token to return a struct:
60
+
61
+ ### `SaveRecommendations.call(api_token:)`
62
+
63
+ ```ruby
64
+ class Photo < Dry::Struct
65
+ attribute :id, Types.string
66
+ attribute? :crop_info do
67
+ attribute? :user do
68
+ attribute :width_pct, Types.float
69
+ attribute :x_offset_pct, Types.float
70
+ attribute :height_pct, Types.float
71
+ attribute :y_offset_pct, Types.float
72
+ end
73
+ attribute? :algo do
74
+ attribute :width_pct, Types.float
75
+ attribute :x_offset_pct, Types.float
76
+ attribute :height_pct, Types.float
77
+ attribute :y_offset_pct, Types.float
78
+ end
79
+ attribute :processed_by_bullseye, Types.bool
80
+ attribute :user_customized, Types.bool
81
+ attribute? :url, Types.string
82
+ attribute? :processedFiles, Types.array
83
+ attribute? :fileName, Types.string
84
+ attribute? :extension, Types.string
85
+ end
86
+ end
87
+
88
+ class User < Dry::Struct
89
+ attribute :_id, Types.string
90
+ attribute :bio, Types.string
91
+ attribute :birth_date, Types.string
92
+ attribute :name, Types.string
93
+ attribute :photos, Types.array.of(Photo)
94
+ attribute :gender, Types.integer
95
+ attribute :jobs, Types.array
96
+ attribute :schools, Types.array do
97
+ attribute :name, Types.string
98
+ end
99
+ attribute? :city do
100
+ attribute :name, Types.string
101
+ end
102
+ attribute? :is_traveling, Types.bool
103
+ attribute? :hide_age, Types.bool
104
+ attribute? :hide_distance, Types.bool
105
+ end
106
+
107
+ # Return this object
108
+ class Recommendation < Dry::Struct
109
+ attribute :type, Types.string
110
+ attribute :user, User
111
+ attribute :facebook do
112
+ attribute :common_connections, Types.array
113
+ attribute :connection_count, Types.integer
114
+ attribute :common_interests, Types.array
115
+ end
116
+ attribute :spotify, Types.hash
117
+ attribute :distance_mi, Types.integer
118
+ attribute :content_hash, Types.string
119
+ attribute :s_number, Types.integer
120
+ attribute :teasers, Types.array do
121
+ attribute :type, Types.string
122
+ attribute :string, Types.string
123
+ end
124
+ end
125
+ ```
126
+
127
+
128
+ ### `SaveUpdates.call(api_token:)`
129
+
130
+ ```ruby
131
+ class Message < Dry::Struct
132
+ attribute :_id, Types.string
133
+ attribute :match_id, Types.string
134
+ attribute :sent_date, Types.string
135
+ attribute :message, Types.string
136
+ attribute :to, Types.string
137
+ attribute :from, Types.string
138
+ attribute :created_date, Types.string
139
+ attribute :timestamp, Types.send('coercible.string')
140
+ end
141
+
142
+ class LikedMessage < Dry::Struct
143
+ attribute :message_id, Types.string
144
+ attribute :updated_at, Types.string
145
+ attribute :liker_id, Types.string
146
+ attribute :match_id, Types.string
147
+ attribute :is_liked, Types.bool
148
+ end
149
+
150
+ class Person < Dry::Struct
151
+ attribute? :bio, Types.string
152
+ attribute :birth_date, Types.string
153
+ attribute :gender, Types.integer
154
+ attribute :name, Types.string
155
+ attribute :ping_time, Types.string
156
+ attribute :photos, Types.array
157
+ end
158
+
159
+ class Match < Dry::Struct
160
+ attribute :_id, Types.string
161
+ attribute :closed, Types.bool
162
+ attribute :common_friend_count, Types.integer
163
+ attribute :common_like_count, Types.integer
164
+ attribute :created_date, Types.string
165
+ attribute :dead, Types.bool
166
+ attribute :following, Types.bool
167
+ attribute :following_moments, Types.bool
168
+ attribute :id, Types.string
169
+ attribute :is_boost_match, Types.bool
170
+ attribute :is_fast_match, Types.bool
171
+ attribute :is_super_like, Types.bool
172
+ attribute :last_activity_date, Types.string
173
+ attribute :message_count, Types.integer
174
+ attribute :messages, Types.array.of(Message)
175
+ attribute :muted, Types.bool
176
+ attribute :participants, Types.array
177
+ attribute :pending, Types.bool
178
+ attribute :person, Person
179
+ attribute :readreceipt, Types.hash
180
+ attribute :seen, Types.hash
181
+ end
182
+
183
+ class Updates < Dry::Struct
184
+ attribute :blocks, Types.array.of(Types.string)
185
+ attribute :deleted_lists, Types.array
186
+ attribute :goingout, Types.array
187
+ attribute :harassing_messages, Types.array
188
+ attribute :inbox, Types.array.of(Message)
189
+ attribute :poll_interval, Types.hash
190
+ attribute :liked_messages, Types.array.of(LikedMessage)
191
+ attribute :lists, Types.array
192
+ attribute :matches, Types.array.of(Match)
193
+ attribute :squads, Types.array
194
+ end
195
+ ```
196
+
@@ -61,7 +61,7 @@ namespace :tinder do
61
61
  client = Tinder::Client.new
62
62
  client.api_token = IO.read(token_path).chomp
63
63
 
64
- feed = client.get_recommended_users
64
+ feed = client.get_recommendations
65
65
  feed.each do |person|
66
66
  puts person
67
67
  end
@@ -0,0 +1,86 @@
1
+ module Tinder
2
+
3
+ class Client
4
+ def get_recommendations(&block)
5
+ if block_given?
6
+ yield get_recommendations && return
7
+ end
8
+
9
+ data = get(endpoint(:recommendations))
10
+
11
+ fail 'Connection Timeout' unless data.dig('data', 'timeout').nil?
12
+
13
+ error_message = data.dig('error', 'message')
14
+ fail 'Rate Limited' if error_message == 'RATE_LIMITED'
15
+ return [] if error_message == 'There is no one around you'
16
+ fail 'Unknown Error' unless error_message.nil?
17
+
18
+ results = Array(data.dig('data', 'results'))
19
+ return [] if results.first.is_a?(String) && results.first == 'You are out of likes today. Come back later to continue swiping on more people.'
20
+
21
+ results.map { |user_data| Recommendation.new(user_data) }
22
+ end
23
+ end
24
+
25
+ class Photo < Dry::Struct
26
+ attribute :id, Types.string
27
+ attribute? :crop_info do
28
+ attribute? :user do
29
+ attribute :width_pct, Types.float
30
+ attribute :x_offset_pct, Types.float
31
+ attribute :height_pct, Types.float
32
+ attribute :y_offset_pct, Types.float
33
+ end
34
+ attribute? :algo do
35
+ attribute :width_pct, Types.float
36
+ attribute :x_offset_pct, Types.float
37
+ attribute :height_pct, Types.float
38
+ attribute :y_offset_pct, Types.float
39
+ end
40
+ attribute :processed_by_bullseye, Types.bool
41
+ attribute :user_customized, Types.bool
42
+ attribute? :url, Types.string
43
+ attribute? :processedFiles, Types.array
44
+ attribute? :fileName, Types.string
45
+ attribute? :extension, Types.string
46
+ end
47
+ end
48
+
49
+ class User < Dry::Struct
50
+ attribute :_id, Types.string
51
+ attribute :bio, Types.string
52
+ attribute :birth_date, Types.string
53
+ attribute :name, Types.string
54
+ attribute :photos, Types.array.of(Photo)
55
+ attribute :gender, Types.integer
56
+ attribute :jobs, Types.array
57
+ attribute :schools, Types.array do
58
+ attribute :name, Types.string
59
+ end
60
+ attribute? :city do
61
+ attribute :name, Types.string
62
+ end
63
+ attribute? :is_traveling, Types.bool
64
+ attribute? :hide_age, Types.bool
65
+ attribute? :hide_distance, Types.bool
66
+ end
67
+
68
+ # Return this object
69
+ class Recommendation < Dry::Struct
70
+ attribute :type, Types.string
71
+ attribute :user, User
72
+ attribute :facebook do
73
+ attribute :common_connections, Types.array
74
+ attribute :connection_count, Types.integer
75
+ attribute :common_interests, Types.array
76
+ end
77
+ attribute :spotify, Types.hash
78
+ attribute :distance_mi, Types.integer
79
+ attribute :content_hash, Types.string
80
+ attribute :s_number, Types.integer
81
+ attribute :teasers, Types.array do
82
+ attribute :type, Types.string
83
+ attribute :string, Types.string
84
+ end
85
+ end
86
+ end
@@ -1,7 +1,9 @@
1
1
  module Tinder
2
2
  class Client
3
3
  # This includes the matches, as well as the messages, so must be parsed
4
- def get_updates(since = Time.now)
4
+ # @return Updates a Dry::Struct object based on a JSON response
5
+
6
+ def get_updates(since: Time.now)
5
7
  response = post(endpoint(:updates))
6
8
 
7
9
  fail 'Connection Timeout' unless response.dig('data', 'timeout').nil?
@@ -13,72 +15,69 @@ module Tinder
13
15
  end
14
16
  end
15
17
 
16
- class Updates < Dry::Struct
18
+ class Message < Dry::Struct
19
+ attribute :_id, Types.string
20
+ attribute :match_id, Types.string
21
+ attribute :sent_date, Types.string
22
+ attribute :message, Types.string
23
+ attribute :to, Types.string
24
+ attribute :from, Types.string
25
+ attribute :created_date, Types.string
26
+ attribute :timestamp, Types.send('coercible.string')
27
+ end
28
+
29
+ class LikedMessage < Dry::Struct
30
+ attribute :message_id, Types.string
31
+ attribute :updated_at, Types.string
32
+ attribute :liker_id, Types.string
33
+ attribute :match_id, Types.string
34
+ attribute :is_liked, Types.bool
35
+ end
36
+
37
+ class Person < Dry::Struct
38
+ attribute? :bio, Types.string
39
+ attribute :birth_date, Types.string
40
+ attribute :gender, Types.integer
41
+ attribute :name, Types.string
42
+ attribute :ping_time, Types.string
43
+ attribute :photos, Types.array
44
+ end
17
45
 
46
+ class Match < Dry::Struct
47
+ attribute :_id, Types.string
48
+ attribute :closed, Types.bool
49
+ attribute :common_friend_count, Types.integer
50
+ attribute :common_like_count, Types.integer
51
+ attribute :created_date, Types.string
52
+ attribute :dead, Types.bool
53
+ attribute :following, Types.bool
54
+ attribute :following_moments, Types.bool
55
+ attribute :id, Types.string
56
+ attribute :is_boost_match, Types.bool
57
+ attribute :is_fast_match, Types.bool
58
+ attribute :is_super_like, Types.bool
59
+ attribute :last_activity_date, Types.string
60
+ attribute :message_count, Types.integer
61
+ attribute :messages, Types.array.of(Message)
62
+ attribute :muted, Types.bool
63
+ attribute :participants, Types.array
64
+ attribute :pending, Types.bool
65
+ attribute :person, Person
66
+ attribute :readreceipt, Types.hash
67
+ attribute :seen, Types.hash
68
+ end
69
+
70
+ class Updates < Dry::Struct
18
71
  attribute :blocks, Types.array.of(Types.string)
19
72
  attribute :deleted_lists, Types.array
20
73
  attribute :goingout, Types.array
21
74
  attribute :harassing_messages, Types.array
22
- attribute :inbox, Types.array do
23
- attribute :_id, Types.string
24
- attribute :match_id, Types.string
25
- attribute :sent_date, Types.string
26
- attribute :message, Types.string
27
- attribute :to, Types.string
28
- attribute :from, Types.string
29
- attribute :created_date, Types.string
30
- attribute :timestamp, Types.send('coercible.string')
31
- end
75
+ attribute :inbox, Types.array.of(Message)
32
76
  attribute :poll_interval, Types.hash
33
- attribute :liked_messages, Types.array do
34
- attribute :message_id, Types.string
35
- attribute :updated_at, Types.string
36
- attribute :liker_id, Types.string
37
- attribute :match_id, Types.string
38
- attribute :is_liked, Types.bool
39
- end
77
+ attribute :liked_messages, Types.array.of(LikedMessage)
40
78
  attribute :lists, Types.array
41
- attribute :matches, Types.array do
42
- attribute :_id, Types.string
43
- attribute :closed, Types.bool
44
- attribute :common_friend_count, Types.integer
45
- attribute :common_like_count, Types.integer
46
- attribute :created_date, Types.string
47
- attribute :dead, Types.bool
48
- attribute :following, Types.bool
49
- attribute :following_moments, Types.bool
50
- attribute :id, Types.string
51
- attribute :is_boost_match, Types.bool
52
- attribute :is_fast_match, Types.bool
53
- attribute :is_super_like, Types.bool
54
- attribute :last_activity_date, Types.string
55
- attribute :message_count, Types.integer
56
- attribute :messages, Types.array do
57
- attribute :_id, Types.string
58
- attribute :match_id, Types.string
59
- attribute :sent_date, Types.string
60
- attribute :message, Types.string
61
- attribute :to, Types.string
62
- attribute :from, Types.string
63
- attribute :created_date, Types.string
64
- attribute :timestamp, Types.send('coercible.string')
65
- end
66
- attribute :muted, Types.bool
67
- attribute :participants, Types.array
68
- attribute :pending, Types.bool
69
- attribute :person do
70
- attribute? :bio, Types.string
71
- attribute :birth_date, Types.string
72
- attribute :gender, Types.integer
73
- attribute :name, Types.string
74
- attribute :ping_time, Types.string
75
- attribute :photos, Types.array
76
- end
77
- attribute :readreceipt, Types.hash
78
- attribute :seen, Types.hash
79
- end
79
+ attribute :matches, Types.array.of(Match)
80
80
  attribute :squads, Types.array
81
-
82
81
  end
83
82
  end
84
83
 
@@ -1,3 +1,3 @@
1
1
  module Tinder
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/tinder.rb CHANGED
@@ -5,7 +5,7 @@ require 'faraday'
5
5
  require 'tinder/client'
6
6
  require 'tinder/profile'
7
7
  require 'tinder/account_settings'
8
- require 'tinder/get_recommended_users'
8
+ require 'tinder/get_recommendations'
9
9
  require 'tinder/get_updates'
10
10
  require 'tinder/profile'
11
11
  require 'tinder/like'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinder_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Clery
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2019-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -161,7 +161,7 @@ files:
161
161
  - lib/tinder.rb
162
162
  - lib/tinder/account_settings.rb
163
163
  - lib/tinder/client.rb
164
- - lib/tinder/get_recommended_users.rb
164
+ - lib/tinder/get_recommendations.rb
165
165
  - lib/tinder/get_updates.rb
166
166
  - lib/tinder/like.rb
167
167
  - lib/tinder/pass.rb
@@ -1,83 +0,0 @@
1
- module Tinder
2
-
3
- class Client
4
- def get_recommended_users(&block)
5
- if block_given?
6
- yield get_recommended_users && return
7
- end
8
-
9
- data = get(endpoint(:recommendations))
10
-
11
- fail 'Connection Timeout' unless data.dig('data', 'timeout').nil?
12
-
13
- error_message = data.dig('error', 'message')
14
- fail 'Rate Limited' if error_message == 'RATE_LIMITED'
15
- return [] if error_message == 'There is no one around you'
16
- fail 'Unknown Error' unless error_message.nil?
17
-
18
- results = Array(data.dig('data', 'results'))
19
- return [] if results.first.is_a?(String) && results.first == 'You are out of likes today. Come back later to continue swiping on more people.'
20
-
21
- results.map { |user_data| RecommendedUser.new(user_data) }
22
- end
23
- end
24
-
25
- # Return this object
26
- class RecommendedUser < Dry::Struct
27
-
28
- attribute :type, Types.string
29
- attribute :user do
30
- attribute :_id, Types.string
31
- attribute :bio, Types.string
32
- attribute :birth_date, Types.string
33
- attribute :name, Types.string
34
- attribute :photos, Types.array do
35
- attribute :id, Types.string
36
- attribute? :crop_info do
37
- attribute? :user do
38
- attribute :width_pct, Types.float
39
- attribute :x_offset_pct, Types.float
40
- attribute :height_pct, Types.float
41
- attribute :y_offset_pct, Types.float
42
- end
43
- attribute? :algo do
44
- attribute :width_pct, Types.float
45
- attribute :x_offset_pct, Types.float
46
- attribute :height_pct, Types.float
47
- attribute :y_offset_pct, Types.float
48
- end
49
- attribute :processed_by_bullseye, Types.bool
50
- attribute :user_customized, Types.bool
51
- attribute? :url, Types.string
52
- attribute? :processedFiles, Types.array
53
- attribute? :fileName, Types.string
54
- attribute? :extension, Types.string
55
- end
56
- end
57
- attribute :gender, Types.integer
58
- attribute :jobs, Types.array
59
- attribute :schools, Types.array do
60
- attribute :name, Types.string
61
- end
62
- attribute? :city do
63
- attribute :name, Types.string
64
- end
65
- attribute? :is_traveling, Types.bool
66
- attribute? :hide_age, Types.bool
67
- attribute? :hide_distance, Types.bool
68
- end
69
- attribute :facebook do
70
- attribute :common_connections, Types.array
71
- attribute :connection_count, Types.integer
72
- attribute :common_interests, Types.array
73
- end
74
- attribute :spotify, Types.hash
75
- attribute :distance_mi, Types.integer
76
- attribute :content_hash, Types.string
77
- attribute :s_number, Types.integer
78
- attribute :teasers, Types.array do
79
- attribute :type, Types.string
80
- attribute :string, Types.string
81
- end
82
- end
83
- end