simplenote_ruby 1.0.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: a7618013907f4df4794d9638e25f4e2dbed93fa016730cd30cac34f136a2e063
4
+ data.tar.gz: f55eda90f3f1a6dd19e2145c286e62a55068282f0b3ee82e76a37da64b621b2d
5
+ SHA512:
6
+ metadata.gz: c4e71a9f56320cd88b956d7f3bc48760257497cc8b1dffa7ea9fb22c9eb1a2f56005564cf2c24e107cfe5e5b4c0bf4fc52ce6e0a1699edccd99ab6d928772c93
7
+ data.tar.gz: 32b301d4031f92fd2d0f7df1723fd47c426708341d6484e2413dfa283b046be286e895b5347aed4da85769b5edd23e5e3f4a1f788845d8c1ce1a53b445c36d9d
@@ -0,0 +1,30 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ version: 2.6.x
20
+
21
+ - name: Publish to RubyGems
22
+ run: |
23
+ mkdir -p $HOME/.gem
24
+ touch $HOME/.gem/credentials
25
+ chmod 0600 $HOME/.gem/credentials
26
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
27
+ gem build *.gemspec
28
+ gem push *.gem
29
+ env:
30
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alpha22jp@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in simplenote_ruby.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simplenote_ruby (0.1.0)
5
+ http-exceptions
6
+ httparty
7
+ uuid
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.3)
13
+ http-exceptions (0.1.2)
14
+ httparty (0.18.0)
15
+ mime-types (~> 3.0)
16
+ multi_xml (>= 0.5.2)
17
+ macaddr (1.7.2)
18
+ systemu (~> 2.6.5)
19
+ mime-types (3.3.1)
20
+ mime-types-data (~> 3.2015)
21
+ mime-types-data (3.2019.1009)
22
+ multi_xml (0.6.0)
23
+ rake (12.3.3)
24
+ rspec (3.9.0)
25
+ rspec-core (~> 3.9.0)
26
+ rspec-expectations (~> 3.9.0)
27
+ rspec-mocks (~> 3.9.0)
28
+ rspec-core (3.9.1)
29
+ rspec-support (~> 3.9.1)
30
+ rspec-expectations (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-mocks (3.9.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.9.0)
36
+ rspec-support (3.9.2)
37
+ systemu (2.6.5)
38
+ uuid (2.3.9)
39
+ macaddr (~> 1.0)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ rake (~> 12.0)
46
+ rspec (~> 3.0)
47
+ simplenote_ruby!
48
+
49
+ BUNDLED WITH
50
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 alpha22jp
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,71 @@
1
+ ![Ruby Gem](https://github.com/alpha22jp/simplenote.rb/workflows/Ruby%20Gem/badge.svg)
2
+
3
+ # SimplenoteRuby
4
+
5
+ Ruby library to interact with [Simplenote](https://app.simmplenote.com/) just like Python library [simplenote.py](https://github.com/mrtazz/simplenote.py).
6
+
7
+ ## Installation
8
+
9
+ Install via gem:
10
+
11
+ $ gem install simplenote_ruby
12
+
13
+ ## Usage
14
+
15
+ First of all, authenticate user and create simplenote object.
16
+ ``` ruby
17
+ import 'simplenote_ruby'
18
+ user = "foo@example.com"
19
+ password = "abcdef"
20
+ sn = Simplenote.new(user, password)
21
+ ```
22
+
23
+ Get all notes:
24
+ ``` ruby
25
+ index = sn.get_index
26
+ index.each do |item|
27
+ note = sn.get_note(item["id"])
28
+ puts "key: #{note["key"]}"
29
+ puts "#{note["content"]}" if note.key?("content")
30
+ end
31
+ ```
32
+
33
+ Update note:
34
+ ``` ruby
35
+ note["content"] = "Test. Test."
36
+ sn.update_note(note)
37
+ ```
38
+
39
+ Create note from text:
40
+ ``` ruby
41
+ sn.create_note("New_note. Test. Test.")
42
+ ```
43
+
44
+ Trash note:
45
+ ``` ruby
46
+ sn.trash_note(note)
47
+ ```
48
+
49
+ Delete note:
50
+ ``` ruby
51
+ sn.delete_note(note)
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ 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).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alpha22jp/simplenote.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/alpha22jp/simplenote.rb/blob/master/CODE_OF_CONDUCT.md).
63
+
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
68
+
69
+ ## Code of Conduct
70
+
71
+ Everyone interacting in the SimplenoteGem project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/alpha22jp/simplenote.rb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simplenote_ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
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
@@ -0,0 +1,3 @@
1
+ module SimplenoteRuby
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,116 @@
1
+ require "simplenote_ruby/version"
2
+ require 'httparty'
3
+ require 'http/exceptions'
4
+ require 'base64'
5
+ require 'uuid'
6
+
7
+ class String
8
+ # TODO: need to handle salogate pair
9
+ def unicode_escape
10
+ self.unpack('U*').map{ |i| i < 0x100 ? i.chr : '\u' + i.to_s(16).rjust(4, '0') }.join
11
+ end
12
+ end
13
+
14
+ class Simplenote
15
+ include HTTParty
16
+ APP_ID = "chalk-bump-f49"
17
+ API_KEY = Base64.decode64("YzhjMmI4NjMzNzE1NGNkYWJjOTg5YjIzZTMwYzZiZjQ=")
18
+ URI_API = "https://api.simperium.com/1/" + APP_ID + "/note/"
19
+ URI_AUTH = "https://auth.simperium.com/1/" + APP_ID
20
+
21
+ def initialize(email, password)
22
+ @email = email
23
+ @password = password
24
+ @token = nil
25
+ end
26
+
27
+ def get_token
28
+ @token ||= authenticate
29
+ end
30
+
31
+ def headers_for_api
32
+ { "X-Simperium-Token" => get_token, "Content-Type" => "application/json" }
33
+ end
34
+
35
+ def authenticate
36
+ res = Http::Exceptions.wrap_and_check do
37
+ headers = { "X-Simperium-API-Key" => API_KEY, "User-Agent" => "simplenote.rb" }
38
+ body = { "username" => @email, "password" => @password }.to_json
39
+ self.class.base_uri(URI_AUTH)
40
+ self.class.post("/authorize/", headers: headers, body: body, format: :json)
41
+ end
42
+ res["access_token"]
43
+ rescue Http::Exceptions::HttpException => e
44
+ puts "Login error: " + e.message
45
+ end
46
+
47
+ def get_index(mark = nil, note_list = [])
48
+ return nil unless get_token
49
+ res = Http::Exceptions.wrap_and_check do
50
+ params = { "data" => true, "limit" => 100 }
51
+ params.merge!("mark" => mark) unless mark.nil?
52
+ self.class.base_uri(URI_API)
53
+ self.class.get("/index", headers: headers_for_api, query: params, format: :json)
54
+ end
55
+ note_list.concat(res["index"])
56
+ res.key?("mark") ? get_index(res["mark"], note_list) : note_list
57
+ rescue Http::Exceptions::HttpException => e
58
+ puts "Get index error: " + e.message
59
+ end
60
+
61
+ def get_note(key)
62
+ return nil unless get_token
63
+ res = Http::Exceptions.wrap_and_check do
64
+ self.class.base_uri(URI_API)
65
+ self.class.get("/i/#{key}", headers: headers_for_api, format: :json)
66
+ end
67
+ res.merge!("key" => key, "version" => res.headers["X-Simperium-Version"].to_i)
68
+ rescue Http::Exceptions::HttpException => e
69
+ puts "Get note #{key} error: " + e.message
70
+ end
71
+
72
+ def update_note(note)
73
+ return nil unless get_token
74
+ key = note.delete("key")
75
+ version = note.delete("version")
76
+ note["modificationDate"] = Time.now.to_f
77
+ res = Http::Exceptions.wrap_and_check do
78
+ params = { "response" => true }
79
+ self.class.base_uri(URI_API)
80
+ self.class.post("/i/#{key}" + (version ? "/v/#{version.to_s}" : ""),
81
+ headers: headers_for_api, query: params,
82
+ body: note.to_json.unicode_escape, format: :json)
83
+ end
84
+ res.merge!("key" => key, "version" => res.headers["X-Simperium-Version"].to_i)
85
+ rescue Http::Exceptions::HttpException => e
86
+ puts 'Update note error: ' + e.message
87
+ end
88
+
89
+ def create_note(note_or_string)
90
+ if note_or_string.is_a?(String)
91
+ note = { "creationDate" => Time.now.to_f, "deleted" => false, "content" => note_or_string,
92
+ "tags" => [], "systemTags" => [], "shareURL" => "", "publishURL" => "" }
93
+ end
94
+ note["key"] = UUID.generate(:compact)
95
+ update_note(note)
96
+ end
97
+
98
+ def trash_note(note)
99
+ note["deleted"] = true
100
+ update_note(note)
101
+ end
102
+
103
+ def delete_note(note)
104
+ return false unless get_token
105
+ # Note has to be trashed before delettion
106
+ note = trash_note(note)
107
+ key = note["key"]
108
+ Http::Exceptions.wrap_and_check do
109
+ self.class.base_uri(URI_API)
110
+ self.class.delete("/i/#{key}", headers: headers_for_api)
111
+ end
112
+ return true
113
+ rescue Http::Exceptions::HttpException => e
114
+ puts 'Delete note error: ' + e.message
115
+ end
116
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/simplenote_ruby/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "simplenote_ruby"
5
+ spec.version = SimplenoteRuby::VERSION
6
+ spec.authors = ["alpha22jp"]
7
+ spec.email = ["alpha22jp@gmail.com"]
8
+
9
+ spec.summary = %q{Ruby library to interact with Simplenote (https://app.simplenote.com/).}
10
+ spec.homepage = "https://github.com/alpha22jp/simplenote.rb"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "httparty"
28
+ spec.add_dependency "http-exceptions"
29
+ #spec.add_dependency "base64"
30
+ spec.add_dependency "uuid"
31
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplenote_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - alpha22jp
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
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: http-exceptions
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: uuid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - alpha22jp@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".github/workflows/gempush.yml"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/simplenote_ruby.rb
75
+ - lib/simplenote_ruby/version.rb
76
+ - simplenote_ruby.gemspec
77
+ homepage: https://github.com/alpha22jp/simplenote.rb
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ homepage_uri: https://github.com/alpha22jp/simplenote.rb
82
+ source_code_uri: https://github.com/alpha22jp/simplenote.rb
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.3.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.0.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Ruby library to interact with Simplenote (https://app.simplenote.com/).
102
+ test_files: []