Skip to content

Commit

Permalink
Merge pull request #53 from pubnub/CE-3291-QueryParams-d-in-grant
Browse files Browse the repository at this point in the history
New features and improvements
  • Loading branch information
crimsonred committed Oct 16, 2018
2 parents 8e61f89 + dd30271 commit 6484c15
Show file tree
Hide file tree
Showing 65 changed files with 1,616 additions and 317 deletions.
19 changes: 18 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
---
changelog:
-
changes:
-
text: "QueryParams in all API calls"
type: feature
-
text: "d in grant"
type: feature
-
text: "maxIdleConnsPerHost setting in config"
type: feature
-
text: "Max concurrent workers for Publish and Grant requests"
type: improvement
date: Oct 16, 18
version: v4.1.4
-
changes:
-
Expand Down Expand Up @@ -269,10 +285,11 @@ supported-platforms:
- "1.8.7"
- "1.9.7"
- "1.10.3"
- "1.11.1"
platforms:
- "FreeBSD 8-STABLE or later, amd64, 386"
- "Linux 2.6 or later, amd64, 386."
- "Mac OS X 10.8 or later, amd64"
- "Windows 7 or later, amd64, 386"
version: "PubNub Go SDK"
version: v4.1.3
version: v4.1.4
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go:
- 1.8.7
- 1.9.7
- 1.10.3
- 1.11.1
- tip

matrix:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# PubNub 4.1.3 client for Go
# PubNub 4.1.4 client for Go
* Go (1.7.6+)

# Please direct all Support Questions and Concerns to Support@PubNub.com
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.3
4.1.4
25 changes: 17 additions & 8 deletions add_channel_channel_group_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ func (b *addChannelToChannelGroupBuilder) Transport(
return b
}

// QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.
func (b *addChannelToChannelGroupBuilder) QueryParam(queryParam map[string]string) *addChannelToChannelGroupBuilder {
b.opts.QueryParam = queryParam

return b
}

// Execute runs AddChannelToChannelGroup request
func (b *addChannelToChannelGroupBuilder) Execute() (
*AddChannelToChannelGroupResponse, StatusResponse, error) {
Expand All @@ -78,15 +85,12 @@ func (b *addChannelToChannelGroupBuilder) Execute() (
}

type addChannelOpts struct {
pubnub *PubNub

Channels []string

pubnub *PubNub
Channels []string
ChannelGroup string

Transport http.RoundTripper

ctx Context
QueryParam map[string]string
Transport http.RoundTripper
ctx Context
}

func (o *addChannelOpts) config() Config {
Expand Down Expand Up @@ -133,10 +137,15 @@ func (o *addChannelOpts) buildQuery() (*url.Values, error) {
}

q.Set("add", strings.Join(channels, ","))
SetQueryParam(q, o.QueryParam)

return q, nil
}

func (o *addChannelOpts) jobQueue() chan *JobQItem {
return o.pubnub.jobQueue
}

func (o *addChannelOpts) buildBody() ([]byte, error) {
return []byte{}, nil
}
Expand Down
41 changes: 41 additions & 0 deletions add_channel_channel_group_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,47 @@ func TestAddChannelRequestBasic(t *testing.T) {

expected := &url.Values{}
expected.Set("add", "ch1,ch2,ch3")

h.AssertQueriesEqual(t, expected, query, []string{"pnsdk", "uuid"}, []string{})

body, err := opts.buildBody()
assert.Nil(err)

assert.Equal([]byte{}, body)
}

func TestAddChannelRequestBasicQueryParam(t *testing.T) {
assert := assert.New(t)

opts := &addChannelOpts{
Channels: []string{"ch1", "ch2", "ch3"},
ChannelGroup: "cg",
pubnub: pubnub,
}
queryParam := map[string]string{
"q1": "v1",
"q2": "v2",
}
opts.QueryParam = queryParam

path, err := opts.buildPath()
assert.Nil(err)
u := &url.URL{
Path: path,
}

h.AssertPathsEqual(t,
fmt.Sprintf("/v1/channel-registration/sub-key/sub_key/channel-group/cg"),
u.EscapedPath(), []int{})

query, err := opts.buildQuery()
assert.Nil(err)

expected := &url.Values{}
expected.Set("q1", "v1")
expected.Set("q2", "v2")
expected.Set("add", "ch1,ch2,ch3")

h.AssertQueriesEqual(t, expected, query, []string{"pnsdk", "uuid"}, []string{})

body, err := opts.buildBody()
Expand Down
28 changes: 18 additions & 10 deletions add_channels_to_push_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ func (b *addPushNotificationsOnChannelsBuilder) DeviceIDForPush(
return b
}

// QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.
func (b *addPushNotificationsOnChannelsBuilder) QueryParam(queryParam map[string]string) *addPushNotificationsOnChannelsBuilder {
b.opts.QueryParam = queryParam

return b
}

// Execute runs add Push Notifications on channels request
func (b *addPushNotificationsOnChannelsBuilder) Execute() (
*AddPushNotificationsOnChannelsResponse, StatusResponse, error) {
Expand All @@ -73,17 +80,13 @@ func (b *addPushNotificationsOnChannelsBuilder) Execute() (
}

type addChannelsToPushOpts struct {
pubnub *PubNub

Channels []string

PushType PNPushType

pubnub *PubNub
Channels []string
PushType PNPushType
DeviceIDForPush string

Transport http.RoundTripper

ctx Context
QueryParam map[string]string
Transport http.RoundTripper
ctx Context
}

func (o *addChannelsToPushOpts) config() Config {
Expand Down Expand Up @@ -138,10 +141,15 @@ func (o *addChannelsToPushOpts) buildQuery() (*url.Values, error) {

q.Set("add", strings.Join(channels, ","))
q.Set("type", o.PushType.String())
SetQueryParam(q, o.QueryParam)

return q, nil
}

func (o *addChannelsToPushOpts) jobQueue() chan *JobQItem {
return o.pubnub.jobQueue
}

func (o *addChannelsToPushOpts) buildBody() ([]byte, error) {
return []byte{}, nil
}
Expand Down
23 changes: 23 additions & 0 deletions add_channels_to_push_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ func TestAddChannelsToPushOptsBuildQuery(t *testing.T) {
assert.Nil(err)
}

func TestAddChannelsToPushOptsBuildQueryParams(t *testing.T) {
assert := assert.New(t)
queryParam := map[string]string{
"q1": "v1",
"q2": "v2",
}

opts := &addChannelsToPushOpts{
Channels: []string{"ch1", "ch2", "ch3"},
DeviceIDForPush: "deviceId",
PushType: PNPushTypeAPNS,
pubnub: pubnub,
QueryParam: queryParam,
}

u, err := opts.buildQuery()
assert.Equal("ch1,ch2,ch3", u.Get("add"))
assert.Equal("apns", u.Get("type"))
assert.Equal("v1", u.Get("q1"))
assert.Equal("v2", u.Get("q2"))
assert.Nil(err)
}

func TestAddChannelsToPushOptsBuildBody(t *testing.T) {
assert := assert.New(t)

Expand Down
4 changes: 2 additions & 2 deletions clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
)

// NewHTTP1Client creates a new HTTP 1 client with a new transport initialized with connect and read timeout
func NewHTTP1Client(connectTimeout int, responseReadTimeout int) *http.Client {
func NewHTTP1Client(connectTimeout, responseReadTimeout, maxIdleConnsPerHost int) *http.Client {
transport := &http.Transport{
// MaxIdleConns: 30,
Dial: (&net.Dialer{
// Covers establishing a new TCP connection
Timeout: time.Duration(connectTimeout) * time.Second,
}).Dial,
MaxIdleConnsPerHost: maxIdleConnsPerHost,
}

client := &http.Client{
Expand Down
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Config struct {
DisablePNOtherProcessing bool // PNOther processing looks for pn_other in the JSON on the recevied message
UseHTTP2 bool // HTTP2 Flag
MessageQueueOverflowCount int // When the limit is exceeded by the number of messages received in a single subscribe request, a status event PNRequestMessageCountExceededCategory is fired.
MaxIdleConnsPerHost int // Used to set the value of HTTP Transport's MaxIdleConnsPerHost.
MaxWorkers int // Number of max workers for Publish and Grant requests
}

// NewDemoConfig initiates the config with demo keys, for tests only.
Expand Down Expand Up @@ -65,6 +67,8 @@ func NewConfig() *Config {
DisablePNOtherProcessing: false,
PNReconnectionPolicy: PNNonePolicy,
MessageQueueOverflowCount: 100,
MaxIdleConnsPerHost: 30,
MaxWorkers: 20,
}

return &c
Expand Down
23 changes: 16 additions & 7 deletions delete_channel_group_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func (b *deleteChannelGroupBuilder) ChannelGroup(
return b
}

// QueryParam accepts a map, the keys and values of the map are passed as the query string parameters of the URL called by the API.
func (b *deleteChannelGroupBuilder) QueryParam(queryParam map[string]string) *deleteChannelGroupBuilder {
b.opts.QueryParam = queryParam

return b
}

// Execute runs the DeleteChannelGroup request.
func (b *deleteChannelGroupBuilder) Execute() (
*DeleteChannelGroupResponse, StatusResponse, error) {
Expand All @@ -58,13 +65,11 @@ func (b *deleteChannelGroupBuilder) Execute() (
}

type deleteChannelGroupOpts struct {
pubnub *PubNub

pubnub *PubNub
ChannelGroup string

Transport http.RoundTripper

ctx Context
Transport http.RoundTripper
QueryParam map[string]string
ctx Context
}

func (o *deleteChannelGroupOpts) config() Config {
Expand Down Expand Up @@ -102,10 +107,14 @@ func (o *deleteChannelGroupOpts) buildPath() (string, error) {

func (o *deleteChannelGroupOpts) buildQuery() (*url.Values, error) {
q := defaultQuery(o.pubnub.Config.UUID, o.pubnub.telemetryManager)

SetQueryParam(q, o.QueryParam)
return q, nil
}

func (o *deleteChannelGroupOpts) jobQueue() chan *JobQItem {
return o.pubnub.jobQueue
}

func (o *deleteChannelGroupOpts) buildBody() ([]byte, error) {
return []byte{}, nil
}
Expand Down
37 changes: 37 additions & 0 deletions delete_channel_group_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,43 @@ func TestDeleteChannelGroupRequestBasic(t *testing.T) {
assert.Equal([]byte{}, body)
}

func TestDeleteChannelGroupRequestBasicQueryParam(t *testing.T) {
assert := assert.New(t)
queryParam := map[string]string{
"q1": "v1",
"q2": "v2",
}

opts := &deleteChannelGroupOpts{
ChannelGroup: "cg",
pubnub: pubnub,
QueryParam: queryParam,
}

path, err := opts.buildPath()
assert.Nil(err)
u := &url.URL{
Path: path,
}
h.AssertPathsEqual(t,
fmt.Sprintf("/v1/channel-registration/sub-key/sub_key/channel-group/cg/remove"),
u.EscapedPath(), []int{})

query, err := opts.buildQuery()
assert.Nil(err)

expected := &url.Values{}
expected.Set("q1", "v1")
expected.Set("q2", "v2")

h.AssertQueriesEqual(t, expected, query, []string{"pnsdk", "uuid"}, []string{})

body, err := opts.buildBody()
assert.Nil(err)

assert.Equal([]byte{}, body)
}

func TestNewDeleteChannelGroupBuilder(t *testing.T) {
assert := assert.New(t)
o := newDeleteChannelGroupBuilder(pubnub)
Expand Down
12 changes: 10 additions & 2 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ import (
)

type endpointOpts interface {
jobQueue() chan *JobQItem
config() Config
client() *http.Client
context() Context
validate() error

buildPath() (string, error)
buildQuery() (*url.Values, error)
buildBody() ([]byte, error)

httpMethod() string
operationType() OperationType
telemetryManager() *TelemetryManager
}

func SetQueryParam(q *url.Values, queryParam map[string]string) {
if queryParam != nil {
for key, value := range queryParam {
q.Set(key, value)
}
}
}

func defaultQuery(uuid string, telemetryManager *TelemetryManager) *url.Values {
v := &url.Values{}

Expand Down Expand Up @@ -76,6 +83,7 @@ func buildURL(o endpointOpts) (*url.URL, error) {
}

signedInput += utils.PreparePamParams(query)
//o.config().Log.Println("signedInput:", signedInput)

signature = utils.GetHmacSha256(o.config().SecretKey, signedInput)
}
Expand Down
Loading

0 comments on commit 6484c15

Please sign in to comment.