pnut 0.1.0

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
+ SHA256:
3
+ metadata.gz: 2ba2df58d128250d60431551a4435cb516251aa8491c311d90de848c036467f4
4
+ data.tar.gz: 8d67246e929c27a53595c9f4f2640ce4592ffbd18547572a2465fc512d5f372c
5
+ SHA512:
6
+ metadata.gz: f458240e88df536c1b9720da6ec71f634ecb9a6d460bb22e0e9a8431d153717e1c452b996421b75ecb604329924c1f8e17ac1245b974f294258a882453d1a69e
7
+ data.tar.gz: 24a485265066d33b57488270104fc856a5429632ba99c673faf493016c2b9c7d7844368afa2303ba7409266f3e5d598db17067c628bdcc83c1cf74869c176b1f
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pnut.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pnut (0.1.0)
5
+ addressable (~> 2.5)
6
+ faraday
7
+ webmock (~> 3.4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.5.2)
13
+ public_suffix (>= 2.0.2, < 4.0)
14
+ coderay (1.1.2)
15
+ crack (0.4.3)
16
+ safe_yaml (~> 1.0.0)
17
+ faraday (0.15.2)
18
+ multipart-post (>= 1.2, < 3)
19
+ hashdiff (0.3.7)
20
+ method_source (0.9.0)
21
+ minitest (5.11.3)
22
+ multipart-post (2.0.0)
23
+ pry (0.11.3)
24
+ coderay (~> 1.1.0)
25
+ method_source (~> 0.9.0)
26
+ public_suffix (3.0.2)
27
+ rake (10.5.0)
28
+ safe_yaml (1.0.4)
29
+ webmock (3.4.2)
30
+ addressable (>= 2.3.6)
31
+ crack (>= 0.3.2)
32
+ hashdiff
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ bundler (~> 1.16)
39
+ minitest (~> 5.0)
40
+ pnut!
41
+ pry (~> 0.11)
42
+ rake (~> 10.0)
43
+
44
+ BUNDLED WITH
45
+ 1.16.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Kai Wood
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,67 @@
1
+ # pnut
2
+
3
+ Convenient wrapper library around the [pnut.io](https://pnut.io) API for Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pnut'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pnut
20
+
21
+ ## Usage
22
+
23
+ The goal of the project is to provide a convenient method for every possible endpoint. For example, if you want to fetch the global timeline and get back an array containing "meta" and "data" as described in the [official documentation of the pnut.io API](https://pnut.io/docs/api/implementation/overview):
24
+
25
+ ```ruby
26
+ require "pnut"
27
+
28
+ pnut = Pnut::Client.new
29
+ pnut.global
30
+ ```
31
+
32
+ Check the docs for an overview to all implemented methods.
33
+
34
+ If we didn't implement an endpoint yet, you can use the `request` method to send custom requests:
35
+
36
+ ```ruby
37
+ require "pnut"
38
+
39
+ pnut = Pnut::Client.new
40
+ pnut.request("/posts/streams/global")
41
+ ```
42
+
43
+ ```ruby
44
+ require "pnut"
45
+
46
+ pnut.request(
47
+ "/channels/123/messages",
48
+ method: "POST",
49
+ data: {
50
+ text: "Der Test[tm]"
51
+ }
52
+ )
53
+ ```
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ 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).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kaiwood/pnut-ruby.
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pnut"
5
+
6
+ @pnut = Pnut::Client.new(authorization_token: ENV["PNUT_TOKEN"])
7
+
8
+ require "pry"
9
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/pnut/posts.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Posts
2
+ # <em>GET /posts/streams/global</em>
3
+ #
4
+ # A stream of all users' public posts.
5
+ def global(**args)
6
+ self.request("/posts/streams/global", params: args)
7
+ end
8
+
9
+ # <em>GET /posts/streams/unified</em>
10
+ #
11
+ # A combined Personal Stream including the authenticated user's mentions.
12
+ def unified(**args)
13
+ self.request("/posts/streams/unified", params: args)
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Pnut
2
+ VERSION = "0.1.0"
3
+ end
data/lib/pnut.rb ADDED
@@ -0,0 +1,37 @@
1
+ require "pnut/version"
2
+ require "pnut/posts"
3
+ require "faraday"
4
+ require "json"
5
+ require "ostruct"
6
+ require "addressable/uri"
7
+
8
+ module Pnut
9
+ class Client
10
+ include Posts
11
+
12
+ def initialize(authorization_token: nil)
13
+ @token = authorization_token
14
+ @connection = Faraday.new("https://api.pnut.io/")
15
+ end
16
+
17
+ def request(endpoint, method: "GET", params: nil, data: nil, raw_response: false)
18
+ prepared_endpoint = "/v0#{endpoint}"
19
+
20
+ if params
21
+ uri = Addressable::URI.new
22
+ uri.query_values = params
23
+ prepared_endpoint += "?#{uri.query}"
24
+ end
25
+
26
+ response = @connection.send(method.downcase.to_sym, prepared_endpoint) do |req|
27
+ req.url prepared_endpoint
28
+ req.headers["Content-Type"] = "application/json"
29
+
30
+ req.headers["Authorization"] = "Bearer #{@token}" if @token
31
+ req.body = data.to_json if data
32
+ end
33
+
34
+ raw_response ? response.body : JSON.parse(response.body, object_class: OpenStruct)
35
+ end
36
+ end
37
+ end
data/pnut.gemspec ADDED
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "pnut/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pnut"
8
+ spec.version = Pnut::VERSION
9
+ spec.authors = ["Kai Wood"]
10
+ spec.email = ["kwood@kwd.io"]
11
+
12
+ spec.summary = %q{Convenient wrapper library around the [pnut.io](https://pnut.io) API}
13
+ spec.homepage = "https://github.com/kaiwood/pnut-ruby"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "faraday"
26
+ spec.add_dependency "webmock", "~> 3.4"
27
+ spec.add_dependency "addressable", "~> 2.5"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+ spec.add_development_dependency "pry", "~> 0.11"
33
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pnut
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kai Wood
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.11'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.11'
111
+ description:
112
+ email:
113
+ - kwood@kwd.io
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/pnut.rb
128
+ - lib/pnut/posts.rb
129
+ - lib/pnut/version.rb
130
+ - pnut.gemspec
131
+ homepage: https://github.com/kaiwood/pnut-ruby
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.7.6
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Convenient wrapper library around the [pnut.io](https://pnut.io) API
155
+ test_files: []