quacker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: feb0536ed22e74d0492ff6931c2782f954a629e3deaf4314fd2c2ec05fc3d4dd
4
+ data.tar.gz: fce2125b68a973ae93b422bc5f1d050b2febf411ce8e8bcc70318567877e4355
5
+ SHA512:
6
+ metadata.gz: 58aee2489725a7197b95cf50c81e5d0101ac1e61630e0a1b68f5175da8b5744cca5e35d6157cec5e6ef79081a3454cc2d99f0cb8788d5aa96710ee84d7282352
7
+ data.tar.gz: 8baa13c91b24f73c701c9263df8a13100fb193efc4ef99c8d6497ff72d54ede1d2f2fe81712a230d468c600bd40016b3c1d0994b4d58398b9193433b4f3120a1
@@ -0,0 +1,5 @@
1
+ *.so
2
+ *.o
3
+ .bundle
4
+ /**/Makefile
5
+ /**/mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ quacker (0.1.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.14.2)
10
+ rake (13.0.1)
11
+ rake-compiler (1.1.1)
12
+ rake
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler
19
+ minitest
20
+ quacker!
21
+ rake
22
+ rake-compiler
23
+
24
+ BUNDLED WITH
25
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 pjshwa
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.
@@ -0,0 +1,29 @@
1
+ # Quacker
2
+
3
+ An important gem that quacks when the weather in Seoul is rainy.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'quacker', git: 'https://github.com/pjshwa/quacker'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ Quacker.new.quack # => "quack" if it is raining, "..." if it is not raining
21
+ ```
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pjshwa/quacker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/extensiontask'
3
+ require 'rake/testtask'
4
+
5
+ task :default => :spec
6
+
7
+ Rake::ExtensionTask.new("quacker") do |extension|
8
+ extension.lib_dir = "lib/quacker"
9
+ end
10
+
11
+ Rake::TestTask.new do |t|
12
+ t.libs << 'test'
13
+ end
14
+
15
+ desc "Run tests"
16
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+
3
+ have_library("curl", "curl_easy_init")
4
+ create_makefile('quacker/quacker') # Create Makefile
@@ -0,0 +1,54 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+ #include <curl/curl.h>
5
+ #include <ruby.h>
6
+
7
+ struct MemoryStruct {
8
+ char *memory;
9
+ size_t size;
10
+ };
11
+
12
+ static size_t
13
+ WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
14
+ {
15
+ size_t realsize = size * nmemb;
16
+ struct MemoryStruct *mem = (struct MemoryStruct *)userp;
17
+
18
+ mem->memory = realloc(mem->memory, mem->size + realsize + 1);
19
+ if(mem->memory == NULL) {
20
+ printf("not enough memory (realloc returned NULL)\n");
21
+ return 0;
22
+ }
23
+
24
+ memcpy(&(mem->memory[mem->size]), contents, realsize);
25
+ mem->size += realsize;
26
+ mem->memory[mem->size] = 0;
27
+
28
+ return realsize;
29
+ }
30
+
31
+ VALUE method_quack_response(VALUE self) {
32
+ CURL *curl_handle;
33
+ struct MemoryStruct chunk;
34
+
35
+ chunk.memory = malloc(1);
36
+ chunk.size = 0;
37
+
38
+ curl_global_init(CURL_GLOBAL_ALL);
39
+ curl_handle = curl_easy_init();
40
+ curl_easy_setopt(curl_handle, CURLOPT_URL, "http://api.openweathermap.org/data/2.5/weather?id=1835848&APPID=ddaa30ea4f531944617c179cc7c1b270");
41
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
42
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
43
+ curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
44
+ curl_easy_perform(curl_handle);
45
+
46
+ // the json segment indicates rainy weather
47
+ // `strstr()` returns index if substring is present
48
+ return rb_sprintf(strstr(chunk.memory, "\"weather\":[{\"id\":5") == NULL ? "..." : "quack");
49
+ }
50
+
51
+ void Init_quacker() {
52
+ VALUE QUACKER = rb_define_class("Quacker", rb_cObject);
53
+ rb_define_method(QUACKER, "quack", method_quack_response, 0);
54
+ }
@@ -0,0 +1,2 @@
1
+ require "quacker/quacker"
2
+ require "quacker/version"
@@ -0,0 +1,3 @@
1
+ class Quacker
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'lib/quacker/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "quacker"
5
+ spec.version = Quacker::VERSION
6
+ spec.authors = ["pjshwa"]
7
+ spec.email = ["pjshwa@gmail.com"]
8
+
9
+ spec.summary = "Quacks when it is raining in Seoul."
10
+ spec.homepage = "https://github.com/pjshwa/quacker"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
14
+ f.match(%r{^(test|spec|features)/})
15
+ end
16
+ spec.extensions = %w[ext/quacker/extconf.rb]
17
+
18
+ spec.add_development_dependency "bundler"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "rake-compiler"
21
+ spec.add_development_dependency "minitest"
22
+ # spec.add_development_dependency "mimic"
23
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quacker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - pjshwa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - pjshwa@gmail.com
72
+ executables: []
73
+ extensions:
74
+ - ext/quacker/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - ext/quacker/extconf.rb
84
+ - ext/quacker/quacker.c
85
+ - lib/quacker.rb
86
+ - lib/quacker/version.rb
87
+ - quacker.gemspec
88
+ homepage: https://github.com/pjshwa/quacker
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.1.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Quacks when it is raining in Seoul.
111
+ test_files: []