zalo-api 0.1.0 → 0.1.1

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: 447c13bb6805ba83d120599a6c6a85fcfb98982d0dde523644ba5320eee0e207
4
- data.tar.gz: 2abc8369eeb4af44b8aee312a67bcb18935c2be581e24e5c6d785db7184fc448
3
+ metadata.gz: dcc02321e2fdf4f94282f384a457d8440e867577fb4348b4f57f0567750fac93
4
+ data.tar.gz: 5615c6cbb03212f65edc4a812ef0302e04a15d85b0c211fc91f2dcd808691cb6
5
5
  SHA512:
6
- metadata.gz: bcc8c7369f2c79f768f6de1b4af7d5fa4e976e700404b215676829597c645e904aad27c09ded1c35a27de9a96f611b6ac2d18cb535b9db7801e92f3977353129
7
- data.tar.gz: b4ef69c50fdc86ff36ffe72fc478442d0d0ec65059a91610c2e47e3debccc241a4f88d825002a14a644e367c0eeea01381311ecc553b6658749f05f744357724
6
+ metadata.gz: daad847ca6eb85c76a7b01513177f1d128420d785cbe3c1cc2ac468787aeaf94845fbbfe6d03980922e90f378fd0c24d6999fb6ede4dbb0bb592cb847c53ae54
7
+ data.tar.gz: 9a8db712713d26f01c16393a46efac3b60c1ebb655b709d27d6aca74a5a527e0fc4f4e13446983fe895e6b955fe8daf518e3f08643e68eeb5d991168035b1cd1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zalo-api (0.1.0)
4
+ zalo-api (0.1.1)
5
5
  addressable
6
6
  faraday
7
7
  json (>= 1.8)
@@ -1,4 +1,4 @@
1
- require 'zalo_api/version'
1
+ require 'zalo_api/client'
2
2
 
3
3
  module ZaloAPI
4
4
  class Error < StandardError; end
@@ -2,6 +2,7 @@ require 'faraday'
2
2
 
3
3
  require 'zalo_api/version'
4
4
  require 'zalo_api/configuration'
5
+ require 'zalo_api/oa'
5
6
  require 'zalo_api/middleware/request/encode_json'
6
7
  require 'zalo_api/middleware/request/url_based_access_token'
7
8
  require 'zalo_api/middleware/response/sanitize_response'
@@ -1,31 +1,11 @@
1
1
  require 'zalo_api/resource'
2
+ require 'zalo_api/offical_account/information'
3
+ require 'zalo_api/offical_account/message'
2
4
 
3
5
  module ZaloAPI
4
6
  # API for Offical Account
5
7
  class OA < Resource
6
- # Get Offical Account profile
7
- def me
8
- @client.connection.get "#{base_url}/oa/getoa"
9
- end
10
-
11
- # Get a list of followers
12
- # @param [Integer] offset Start position in the list of people followers
13
- # @param [Integer] count Number of follower people want to take
14
- # @return [Hash] List user_id
15
- # {
16
- # "error": int,
17
- # "message": String,
18
- # "data": {
19
- # "total": int,
20
- # "followers": [
21
- # {
22
- # "user_id": String
23
- # },...
24
- # ]
25
- # }
26
- # }
27
- def followers(offset: 0, count: 5)
28
- @client.connection.get "#{base_url}/oa/getfollowers", { data: { offset: offset, count: count }.to_json }
29
- end
8
+ include ZaloAPI::OfficalAccount::Information
9
+ include ZaloAPI::OfficalAccount::Message
30
10
  end
31
11
  end
@@ -0,0 +1,111 @@
1
+ module ZaloAPI
2
+ module OfficalAccount
3
+ module Information
4
+ # Get Offical Account profile
5
+ def me
6
+ @client.connection.get "#{base_url}/oa/getoa"
7
+ end
8
+
9
+ # Get a list of followers
10
+ #
11
+ # @param [Integer] offset Start position in the list of people followers
12
+ # @param [Integer] count Number of follower people want to take
13
+ # @return [Faraday::Response] List user_id
14
+ #
15
+ # @example
16
+ # res = ZaloAPI::OA.new(client).followers
17
+ # res.body
18
+ # {
19
+ # "error": int,
20
+ # "message": String,
21
+ # "data": {
22
+ # "total": int,
23
+ # "followers": [
24
+ # {
25
+ # "user_id": String
26
+ # },...
27
+ # ]
28
+ # }
29
+ # }
30
+ def followers(offset = 0, count = 5)
31
+ param = { offset: offset, count: count }
32
+ @client.connection.get "#{base_url}/oa/getfollowers", { data: param.to_json }
33
+ end
34
+
35
+ # Get a list of the most recent messages
36
+ def recent_chat(offset = 0, count = 5)
37
+ param = { offset: offset, count: count }
38
+ @client.connection.get "#{base_url}/oa/listrecentchat", { data: param.to_json }
39
+ end
40
+
41
+ # Get profile of follower
42
+ #
43
+ # @param [String] user_id Support user_id or phone with country code (ex: 84)
44
+ # @example
45
+ # conn.get_user_profile('84123456789')
46
+ # {
47
+ # "error": int,
48
+ # "message": String,
49
+ # "data": {
50
+ # "user_gender": int,
51
+ # "user_id": Long,
52
+ # "user_id_by_app": Long,
53
+ # "avatar": String,
54
+ # "avatars": {
55
+ # "120": String,
56
+ # "240": String
57
+ # },
58
+ # "display_name": String,
59
+ # "birth_date": int,
60
+ # "shared_info": String,
61
+ # "tags_and_notes_info": {
62
+ # "tag_names": Array,
63
+ # "notes": Array
64
+ # }
65
+ # }
66
+ # }
67
+ def get_user_profile(user_id)
68
+ @client.connection.get "#{base_url}/oa/getprofile", { data: { user_id: user_id }.to_json }
69
+ end
70
+
71
+ # Get a list of messages with interested people
72
+ #
73
+ # @param [String] user_id
74
+ # @param [Integer] offset
75
+ # @param [Integer] count
76
+ # @return [Faraday::Response]
77
+ #
78
+ # @example
79
+ # res = conn.get_conversation_with_user('2512523625412515')
80
+ # res.body
81
+ # {
82
+ # "error": int,
83
+ # "message": String,
84
+ # "data": [
85
+ # {
86
+ # "msg_id": String,
87
+ # "src": int,
88
+ # "time": int,
89
+ # "type": String,
90
+ # "message": String,
91
+ # "links": JsonObject,
92
+ # "thumb": String,
93
+ # "url": String,
94
+ # "description": String,
95
+ # "from_id": Long,
96
+ # "to_id": Long,
97
+ # "from_display_name": "Huỳnh Hồng Hiển",
98
+ # "from_avatar": String,
99
+ # "to_display_name": String,
100
+ # "to_avatar": String,
101
+ # "location": String
102
+ # },...
103
+ # ]
104
+ # }
105
+ def get_conversation_with_user(user_id, offset = 0, count = 5)
106
+ param = { user_id: user_id, offset: offset, count: count }
107
+ @client.connection.get "#{base_url}/oa/conversation", { data: param.to_json }
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,24 @@
1
+ module ZaloAPI::OfficalAccount
2
+ module Message
3
+ # Send message to user_id
4
+ # @param [String] user_id
5
+ # @param [String] message
6
+ def send_text_message(user_id, message)
7
+ execute(user_id, message)
8
+ end
9
+
10
+ private
11
+
12
+ def execute(user_id, text, attachment = {})
13
+ payload = {
14
+ recipient: { user_id: user_id },
15
+ message: {
16
+ text: text,
17
+ attachment: attachment
18
+ }
19
+ }
20
+
21
+ @client.connection.post "#{base_url}/oa/message", payload
22
+ end
23
+ end
24
+ end
@@ -1,4 +1,4 @@
1
1
  module ZaloAPI
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zalo-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Hùng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-15 00:00:00.000000000 Z
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -123,6 +123,8 @@ files:
123
123
  - lib/zalo_api/middleware/response/parse_json.rb
124
124
  - lib/zalo_api/middleware/response/sanitize_response.rb
125
125
  - lib/zalo_api/oa.rb
126
+ - lib/zalo_api/offical_account/information.rb
127
+ - lib/zalo_api/offical_account/message.rb
126
128
  - lib/zalo_api/resource.rb
127
129
  - lib/zalo_api/version.rb
128
130
  - zalo-api.gemspec